목록js (166)
N
https://leetcode.com/problems/letter-case-permutation/ Letter Case Permutation - 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 백트랙킹 활용. dfs() 함수에 s와 시작 인덱스 0을 넘겨 시작한다. 만약 i === s.length와 같다면 answer에 지금까지 진행한 문자열 s를 넣고 종료한다. 그렇지 않다면 계속 문자열을 탐색한다. 현재 i번째 인덱스가 문자라면 대문자로 바꾸거나 소문자로 바꿔..
https://leetcode.com/problems/rotting-oranges/ Rotting Oranges - 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 BFS 활용. m x n 크기의 grid를 BFS 전에 한번 훑어준다. grid를 순회하면서 멀쩡한 오렌지(grid[i][j] === 1)가 있으면 orange++을 한다. 그렇지 않고 썩은 오렌지(grid[i][j] === 2)가 있다면 queue에 해당 좌표를 넣어준다. 한번 순회가 끝나고, ora..
https://leetcode.com/problems/permutation-in-string/ Permutation in String - 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 HashMap을 이용. 문제는 풀었지만 시간이 간당간당하게 통과해서, 더 큰 문자열이 들어오면 다른 알고리즘을 써야할 것 같다. 투포인터를 이용한 문제인 것 같다. map을 선언해서 s1에 존재하는 모든 문자를 카운팅한다. 이후 s2를 순회하면서, map에 해당 문자가 있는지 확인..
https://leetcode.com/problems/max-area-of-island/ Max Area of Island - 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 BFS 탐색 이용. m x n 크기의 visited 배열을 false로 초기화. 4방향 탐색을 위한 direct 배열도 선언. answer = 탐색한 area 중 가장 큰 값을 저장한다. bfs 함수는 x, y 값을 매개 변수로 받으며, 이 값을 통해 인접한 4방향 중 1로 된 영역의 크기를..
https://leetcode.com/problems/flood-fill/ Flood Fill - 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 BFS 알고리즘. m x n 크기의 visited 배열을 선언하여 false로 초기화. 4 방향을 탐색하기 위한 direct 배열 또한 선언. color는 image[sr][sc]에 해당하는 숫자로, 탐색을 할 때 해당 숫자와 같으면 newColor로 바꾼다. image[sr][sc] = newColor로 하고, que..
https://leetcode.com/problems/shuffle-an-array/ Shuffle an Array - 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 피셔-예이츠 셔플을 이용해 배열을 섞을 수 있다. Solution이라는 class를 이용해 reset()과 shuffle()을 구현. 생성자로는 nums 배열을 받고, original 배열을 통해 reset 시 현재 배열을 원래 배열로 되돌린다. 현재 배열의 상태는 nums라는 배열로 선언했다. r..
https://leetcode.com/problems/populating-next-right-pointers-in-each-node/ Populating Next Right Pointers in Each Node - 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 BFS를 이용. BFS에 이용할 queue와 같은 레벨에 있는 노드를 담을 stack을 빈 배열로 선언. answer = root로 정의. 또 다른 pointer를 root로 지정하고, count는 현재..
https://leetcode.com/problems/triangle/ Triangle - 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 DP 알고리즘. 삼각형으로 이뤄진 배열에서 최소합을 구하면 된다. 최소합을 구하는 조건은 다음 행의 인접한 두 수 중 더 작은 값을 현재 행 값과 더하면 된다. const minimumTotal = (triangle) => { const length = triangle.length; for(let i = length - 2; ..