알고리즘/알고리즘 문제 복기
-
Leet Code - 48. Rotate Image알고리즘/알고리즘 문제 복기 2021. 3. 30. 08:32
leetcode.com/problems/rotate-image/ Rotate Image - 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 Answer1. 각 배열의 값을 전부 돌려주는 방식 Answer2. 행과 열을 바꿔주는 transpose를 수행하고 reflect를 해주어서 변환시켜주는 방식 위 이미지와 같이 배열을 90도 회전한 결과는 배열을 Transpose시켜주고 reflect 시켜준 것과 같다.
-
LeetCode - 46. Permutation알고리즘/알고리즘 문제 복기 2021. 3. 29. 08:32
leetcode.com/problems/permutations/ Permutations - 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 Answer 이번에도 백트레킹 문제 Permutation의 조합을 전부 구하는 문제였다. used로 이미 사용한 수를 체크하여 백트래킹 시켜 풀어냈다. 아니면 다음과 같이 현재 남은 수를 체킹하여 풀어낼 수도 있다. Reference www.youtube.com/watch?v=idmgLLNIC2U www.youtube.com/..
-
Leet code - 55. Jump Game알고리즘/알고리즘 문제 복기 2021. 3. 26. 09:31
leetcode.com/problems/jump-game/ Jump Game - 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 Question. Answer 이전에 점프게임II를 풀어서 그런지 비교적 쉽게 풀어냈다. farthest는 가장 멀리 도달한 인덱스 값이며 nums[i]가 0이라면 그 값에 도달하기 전의 farthest를 체크하여 만약 zero_index보다 멀리 갈 수 있다면 jumpable을 true로 놔두고 아니라면 jumpable를 false로 ..
-
Leet Code - 45. Jump Game II알고리즘/알고리즘 문제 복기 2021. 3. 26. 07:25
leetcode.com/problems/jump-game-ii/ Answer 그리디 방식으로 문제를 풀어야 한다고 한다. 맨처음에 풀어야한다고 할 때 1) nums[i]만큼 탐색 2) nums[i]만큼 이동한거보다 더 큰 값으로 이동하는 값이 있으면 그 값으로 이동 이라는 생각을 했었는데 방향성은 어느정도 맞았지만 구현해내는 방법이 틀려 풀어내지 못했었다. farthest라는 값을 통해 가장 멀리 간 값을 구해내고 curr_end에 i가 도달하면 curr_end를 farthest로 변경해주는 방식이다. www.youtube.com/watch?v=cfdwhSmLt3w&t=443s
-
LeetCode 39. - Combination Sum알고리즘/알고리즘 문제 복기 2021. 3. 24. 16:21
leetcode.com/problems/combination-sum/ Combination Sum - 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 Q Answer. 문제를 처음봤을때 예전에 풀었던, 하나 혹은 두개의 계단을 오르는 방법이 있을 때 계단을 오르는 경우의 수를 구하는 문제가 생각났었다. 그 뒤에 계속 생각하다보니 백트래킹을 사용해야겠다는 생각이나서 풀었었지만 구현력이 되지 않아 풀지 못했었다. 백트래킹에 관한 관련 문제를 더 풀어봐야겠다. www...
-
Leet Code - 34. Find First and Last Position of Element in Sorted Array알고리즘/알고리즘 문제 복기 2021. 3. 24. 07:26
leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/ Find First and Last Position of Element in Sorted 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 Answer 바이너리 서치를 활용해서 푸는 문제였다. 다소 난잡하게 코드를 짠 것 같아 답지를 보니 다음과 같이 풀었었다.
-
LeetCode - 19. Remove Nth Node From End of List알고리즘/알고리즘 문제 복기 2021. 3. 17. 21:08
leetcode.com/problems/remove-nth-node-from-end-of-list/ Remove Nth Node From End of List - 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 Q. Answer. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 ..
-
Leet Code - 11. Container With Most Water알고리즘/알고리즘 문제 복기 2021. 3. 14. 15:19
leetcode.com/problems/container-with-most-water/ Container With Most Water - 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 Answer1. BRUTE FORCE 맨처음에는 단순하게 브루트 포스 방식으로 풀어봤다. 입력되는 값이 10^5길이의 배열까지 있다보니 역시 시간 초과가 나왔다. 풀어보려고 생각해본게 배열에서 height[i]의 크기가 클 때에만 값을 체크하는 것과 배열의 left와 right의 ..