전체 글

전체 글

    Conditional Rendering

    React에서는 if문, &&, ? : 연산자와 같은 JavaScript 구문을 사용해서 JSX를 조건부로 렌더링할 수 있다. 조건부 JSX 반환 if문 if문을 사용하면 조건에 따라 다음과 같이 조건부 렌더링이 가능하다. if (isPacked) { return {name} ✔; } return {name}; 삼항 연산자 return ( {isPacked ? name + ' ✔' : name} ); 논리 AND 연산자(&&) return ( {name} {isPacked && '✔'} ); 해당 연산자에 대한 설명은 이미 전에 정리한 포스팅이 있으므로 아래 참고 바란다 (조건부 렌더링에 대한 설명 링크) JSX를 변수에 조건부로 할당 위에서는 if문을 통해서 바로 조건에 따라 JSX를 반환해주었지만, ..

    LeetCode / Design / 155번 / Min Stack / JS

    Min Stack - LeetCode Can you solve this real interview question? Min Stack - Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the MinStack class: * MinStack() initializes the stack object. * void push(int val) pushes t leetcode.com stack의 메소드들을 구현하는데 추가로 getMin()을 구현한다. getMin()은 스택의 값중에서 가장 작은값을 반환한다. 그 외 기본 메소드는..

    LeetCode / Design / 232번 / Implement Queue using Stacks / JS

    Implement Queue using Stacks - LeetCode Can you solve this real interview question? Implement Queue using Stacks - Implement a first in first out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue (push, peek, pop, and empty). Implement t leetcode.com queue의 메소드인 push, peek, pop, empty를 두 개의 stack을 이용해서 구현한다. var M..

    LeetCode / Tree / 199번 / Binary Tree Right Side View / JS

    Binary Tree Right Side View - LeetCode Can you solve this real interview question? Binary Tree Right Side View - Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Example 1: [https://asse leetcode.com 주어진 트리에서 각 depth(layer) 마다의 가장 오른쪽 노드만 모아서 반환하는 문제이다. /** * Definiti..

    LeetCode / Tree / 101번 / Symmetric Tree / JS

    Symmetric Tree - LeetCode Can you solve this real interview question? Symmetric Tree - Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center). Example 1: [https://assets.leetcode.com/uploads/2021/02/19/symtree1.jpg] Input: roo leetcode.com 주어진 트리가 좌우대칭을 이루는지 판별하여 boolean 값을 반환하는 문제이다. /** * Definition for a binary tree ..

    LeetCode / Tree / 100번 / Same Tree / JS

    Same Tree - LeetCode Can you solve this real interview question? Same Tree - Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the leetcode.com 주어진 두 트리가 구조적으로 같은 트리인지 판단해서 boolean 값을 반환하는 문제이다. /** * Definition for a binary tre..