알고리즘
-
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의 ..
-
Leet code - 5. Longest Palindromic Substring(Java)알고리즘/알고리즘 문제 복기 2021. 3. 14. 12:55
leetcode.com/problems/longest-palindromic-substring/ Longest Palindromic Substring - 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 이전에 풀었었는데 다시 한번 풀려고하니 잘 풀리지가 않았다. 맨처음에는 checkPalindrome이라는 메소드를 만들어 스트링의 중간을 구한 뒤 좌측과 우측으로 확장하며 palindrome인 것을 check하도록 문제를 만들었었는데 O(n^3)의 ..
-
Leetcode - 3. Longest SubString Without Repeating Characters알고리즘/알고리즘 문제 복기 2021. 3. 8. 21:37
leetcode.com/problems/longest-substring-without-repeating-characters/ Longest Substring Without Repeating Characters - 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. 슬라이딩 윈도우 방식을 이용했다. left에서 right까지 훑는 dummy라는 변수를 만들고 dummy의 값이 right와 같다면 dummy+1의 값으로 left로 이동시키는 방식으로 풀었다..
-
Leet code - 2. Add Two Number - Java알고리즘/알고리즘 문제 복기 2021. 3. 8. 20:47
leetcode.com/problems/add-two-numbers/ Add Two Numbers - 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 이전에 C++로 풀었던 것을 자바로 다시 한번 복기할겸 풀었다. 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 48 49 50 ..
-
Leetcode - 155. Min Stack알고리즘/알고리즘 문제 복기 2021. 2. 27. 15:56
leetcode.com/problems/min-stack/ Min Stack - 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 Stack을 구현하는 문제. 처음엔 vector를 이용해서 풀어보려 했는데 자바에서 Vector는 Depreciate되어서 지원하지 않는다고 한다.
-
LeetCode - 617. Merge Two Binary Trees알고리즘/알고리즘 문제 복기 2021. 2. 26. 23:50
leetcode.com/problems/merge-two-binary-trees/ Merge Two Binary Trees - 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 처음에는 output_node를 따로 만들어서 풀어보려 했지만 NullPointerException때문에 계속해서 에러가 나는 바람에 기존의 root1을 변경하는 식으로 코드를 짰다.
-
LeetCode - 543. Diameter of Binary Code알고리즘/알고리즘 문제 복기 2021. 2. 26. 19:42
leetcode.com/problems/diameter-of-binary-tree/ Diameter of Binary 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 처음에는 무조건 root 노드를 통과해야 가장 긴 diameter가 생성된다고 생각해서 다음과 같이 코드를 짰었다 left depth와 right depth를 더해서 max diameter를 구하는 방식으로 했었는데 아무해도 다음과 같을때 에러가 나는 경우가 있었다. 위와같은 트리가 있을..
-
LeetCode - 141. Linked List Cycle알고리즘/알고리즘 문제 복기 2021. 2. 16. 23:28
leetcode.com/problems/linked-list-cycle/ Linked List Cycle - 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. 계속해서 다음 Linked List로 next를 해줘서 반복되는 구간을 찾아보고 어느정도 반복된다면 true를 리턴하기 2. 주소값을 저장하는 배열을 만들고 포인터를 만든 뒤 그 포인터를 추적해서, 이전의 주소의 객체를 방문한다면 true를 리턴하기. 각..