전체 글
-
52. N-Queens II javascriptAlgorithm/LeetCode 이모저모 2023. 5. 19. 11:45
https://leetcode.com/problems/n-queens-ii/description/ /** * @param {number} n * @return {number} */ var cnt = 0; var totalNQueens = function(n) { cnt = 0; let arr = []; nqueen(arr, n); return cnt }; const nqueen = (temp, n) => { if (temp.length === n) { cnt += 1 return } for(let i = 0; i < n; i++) { if (isPossible(temp, i)) { temp.push(i) nqueen(temp, n) temp.pop(i) } } } const isPossible = (ar..
-
51. N-Queens javascriptAlgorithm/LeetCode 이모저모 2023. 5. 19. 11:39
https://leetcode.com/problems/n-queens/description/ /** * @param {number} n * @return {string[][]} */ var solveNQueens = function(n) { let ans = []; let temp = []; nQueen(n, ans, temp); return ans; }; const nQueen = (n, ans, temp) => { if (temp.length === n) { makeAns(ans, temp); return } for(let start = 0; start < n; start++) { if (isPossible(start, temp)) { temp.push(start); nQueen(n, ans, tem..
-
1143. Longest Common Subsequence javascriptAlgorithm/LeetCode 이모저모 2023. 5. 16. 23:11
https://leetcode.com/problems/longest-common-subsequence/ Longest Common Subsequence - LeetCode Can you solve this real interview question? Longest Common Subsequence - Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string genera leetcode.com /** * @param {string} text1 * @p..
-
300. Longest Increasing Subsequence javascriptAlgorithm/LeetCode 이모저모 2023. 5. 16. 22:20
https://leetcode.com/problems/longest-increasing-subsequence/description/ Longest Increasing Subsequence - LeetCode Can you solve this real interview question? Longest Increasing Subsequence - Given an integer array nums, return the length of the longest strictly increasing subsequence. Example 1: Input: nums = [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest leetcode.com # 틀린 풀이 : O(n),..
-
13. Roman to Integer javascriptAlgorithm/LeetCode 이모저모 2023. 5. 12. 15:57
https://leetcode.com/problems/roman-to-integer/description/ /** * @param {string} s * @return {number} */ var romanToInt = function(s) { let map = new Map(); map.set('M', 1000); map.set('D', 500); map.set('C', 100); map.set('L', 50); map.set('X', 10); map.set('V', 5); map.set('I', 1); let sum = 0; for (let i = 0; i < s.length; i++) { if (i < s.length - 1 && map.get(s[i]) < map.get(s[i+1])) { sum..
-
Next.js 렌더링 방식 및 react-query를 이용한 hydrateFrontend/NextJS 2023. 5. 1. 21:41
1. next.js가 SSR을 수행하는 방식 웹서버에서 html+css+js를 다운받아 렌딩할 때 두 가지 방식이 있다. CSR과 SSR. 이 둘의 차이는 이전 포스팅에서 확인할 수 있다. https://lulu-developmentlog.tistory.com/187 nextJS 왜 쓰는가 NextJS에 대한 설명을 구글에서 가져오면 아래와 같다. nextJs는 서버 사이트 렌더링, 정적 웹 페이지 생성 등 리액트 기반 웹 애플리케이션 기능들을 가능케 하는 Node.js 위에서 빌드된 오픈 소스 웹 lulu-developmentlog.tistory.com next.js는 기본적으로 SSR를 기반으로 한다. 하지만 SSR은 처음 및 초기 로딩속도는 빠르지만 페이지를 넘길 때마다 중복되는 데이터를 서버측에서..
-
next.js getInitialProps, getServerSideProps, getStaticProps, getStaticPath,Frontend/NextJS 2023. 5. 1. 15:47
여러 Next.js 프로젝트를 보다보면 흔하게 getInitialProps, getStaticPath, getStaticProps, getServerSideProps들을 마주하곤 한다. 이들의 역할을 쉽게 생각하면 React의 useEffect의 역할을 생각하면 쉽다. React의 useEffect의 경우 렌더링 전 사전에 data를 fetching하기 위해 사용된다. next에서도 이같은 기능을 getInitialProps, getStaticPath, getStaticProps, getServerSideProps를 통해 제공한다. 각각의 종류를 하나하나 자세히 살펴보자. 1. getInitialProps 이름에서 쉽게 유추할 수 있 듯, getInitialProps는 서버에서 실행되어 data를 미리 ..
-
Next.js _app, _documnetFrontend/NextJS 2023. 5. 1. 14:25
yarn create next-app --typescript를 통해 next.js 기본설정을 마치다보면 자동으로 _app.tsx, _document.tsx가 설치되어있는 모습을 볼 수 있다. 이 두가지는 next.js에 어떤 역할을 주는지 알아보자! 1. _app.tsx 기본적으로 Next.js에서는 App의 구성 요소를 사용하여 모든 페이지를 초기화한다. 따라서 App.tsx를 만들어 기본 App 구성 요소를 덮어 쓸 수 있다. 즉, 모든 페이지에서 공통으로 필요한 처리를 여기에서 작성하여 쓰면 된다. 이를테면 - 페이지 간 공통 레이아웃 - 전역 State (Store,React-query 설정 등) - 글로벌 CSS - 각 Route Provider - 상태관리 library의 Provider, R..