본문 바로가기

분류 전체보기33

[React] useState 사용법 정리 useState 개요 React 16.8 이전 버전에서는 함수형 컴포넌트에서 상태를 관리할 수 없었지만, React는 React 16.8에서 Hook이라는 개념을 추가하며 Hook을 통해 class를 작성하지 않고도 state와 같은 React 기능들을 사용할 수 있습니다. 오늘은 Hook 중 하나인 use.State를 정리하겠습니다. useState 변수 선언 import React, { useState } from 'react'; 리액트에서 useState 함수를 불러옵니다. function 예제() { const [state, setState] = useState(0); //const [상태값 저장, 상태값 갱신 변수] = useState(초기값); useState는 상태 변수와 상태를 갱신할 수 .. 2022. 8. 6.
[LeetCode] 101. Symmetric Tree 풀이 (JS) 0. 문제 https://leetcode.com/problems/symmetric-tree/ Symmetric Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 입력값 이진 트리가 주어지면 그것이 자신의 거울인지 (즉, 중심을 중심으로 대칭인지) 확인하는 문제 1.언어 자바스크립트(JavaScript) 2. 문제 풀이 var isSymmetric = function(root) { return isSameTree(root, root); }; functio.. 2022. 7. 24.
[LeetCode] 100. Same Tree 풀이 (JS) 0. 문제 https://leetcode.com/problems/same-tree/submissions/ Same Tree - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 입력값 두 이진 트리가 구조적으로 동일하고 노드가 동일한 값을 갖는 경우 true를 출력 아닐 경우 false를 출력한다. 두 개의 이진 트리가 구조적으로 동일하고 노드가 동일한 값을 갖는 경우 동일한 것으로 간주된다. #1 Input: p = [1,2,3], q = [1,2,3] Outpu.. 2022. 7. 24.
[LeetCode] 15. 3Sum 풀이 (JS) 0. 문제 https://leetcode.com/problems/3sum/ 3Sum - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 숫자로 이루어진 배열이 주어 질 때, 합이 0이 되는 세개의 원소를 배열로 리턴 #1 Input: nums = [-1,0,1,2,-1,-4] Output: [[-1,-1,2],[-1,0,1]] Explanation: nums[0] + nums[1] + nums[2] = (-1) + 0 + 1 = 0. nums[1] + nums[2.. 2022. 7. 24.