leetcode 14

[java] Number of Islands

[참고문제] : https://leetcode.com/problems/number-of-islands/ Number of Islands - 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/BFS 문제이고, 연결된 구간의 갯수를 찾는 문제다. 특히나, 전형적인 문제라 BFS로 풀어보기로 했다. 생각의 흐름 - 방문 여부는 누적되도 된다. 이전에 풀었던 문제는 중복적으로 체크하면 안되었기 때문에, 다시 돌려주는 방법을 사용했지만 이번에는 중복해서 활..

Algorithm 2022.07.16

[java] Word Search

[참고문제] : https://leetcode.com/problems/word-search/ Word Search - 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 문제다. 생각의 흐름 - Recursive하게 풀어보자. DFS는 Stack을 사용하거나, Recursive로 풀면 된다. 이 문제는 Stack을 사용하기 보단, 파라미터가 많아 Recursive하게 풀어주면 좀 더 편하게 풀 수 있을 것으로 생각했다. 생각의 흐름 - 좌,..

Algorithm 2022.07.16

[java] Minimum Size Subarray Sum

[참고문제] : https://leetcode.com/problems/minimum-size-subarray-sum/ Minimum Size Subarray 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 문제 풀이 연속된 subArray를 어떻게 관리할지가 포인트인 문제다. 생각의 흐름 - 한번만 배열을 읽자 물론 문제를 풀면서 달라질 수 있지만, 일단 주어진 nums배열은 한번만 읽는게 중요할 것으로 보였다. 생각의 흐름 - SubArray를 어떻게..

Algorithm 2022.07.16

[java] Find Minimum in Rotated Sorted Array

[참고문제] : https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/ Find Minimum in Rotated 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 문제 풀이 이미 정렬되어 있지만, Rotate되어있는 배열에 대해 최소값을 찾는 문제다. 생각의 흐름 - 양쪽에서 바라보자. 이미 정렬이 되어 있으니, 최소값을 찾는 것에만 집중해야 한다. 그 중에서도 양쪽에서 ..

Algorithm 2022.07.14

[java] House Robber

[참고문제] : https://leetcode.com/problems/house-robber/ House Robber - 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 문제다. 점화식을 찾기 위해서 나열해보자. 이번에도 꽤 많이 나열해보았다. 생각의 흐름 - 초깃값 찾기 이번에도 초깃값부터 찾아보았다. arr[n] 부터 생각해보았으나, 역시 최초 1일때부터 고민하는 것이 나았다. 6번째 정도 적어보니, 이전에 적어둔 식들이 다시 쓰이기 시작했다...

Algorithm 2022.07.05

[java] Climbing Stairs

[참고문제] :https://leetcode.com/problems/climbing-stairs/ Climbing Stairs - 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문제다. DP는 일단 규칙찾기, 점화식 찾기다. 못찾으면 끝나는 문제라고 할 수 있다. 생각의 흐름 - 초기값들을 찾자. 문제에서 보이듯, n = 1, n = 2, n = 3일 때를 보여주고 있다. 점화식 문제처럼 초기값들을 먼저 설정해보자. 생각의 흐름 - 일단 적어보자...

Algorithm 2022.07.05

[java] Flood Fill

[참고문제] :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혹은 DFS 문제임을 알아야 한다. 이차원 배열과 queue, 그리고 적절한 Pair와 같은 자료구조가 필요하다. java에서는 pair와 같은게 없기 때문에, Node라는 class를 만들어 ..

Algorithm 2022.07.04

[java] Longest Substring Without Repeating Characters

[참고문제] : https://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 문제 풀이 MAP을 써야 하는 문제라는 걸 인식했다. 생각의 흐름 - MAP을 어떻게 구성할까? 인덱스를 갖고 있어야 한다고 생각했다. 똑같은게 나왔을 때, 기존 인덱스를 어..

Algorithm 2022.07.04

[java] Remove Nth Node From End of List

[참고문제] : https://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 문제 풀이 자체적인 자료구조를 제공하고 푸는 문제다. 자바는 Call By Value지만, 그 주소값(정확히는 주소를 가리키는 값)을 가지므로 마치 Call By Reference처럼 동작한다. 위 문장에 가끔 Deep Cop..

Algorithm 2022.07.02

[java] Container With Most Water

[참고문제] : https://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 문제 풀이 간단히 2중 포문으로 풀 수 있겠지만, Time 제한에 걸릴게 뻔해보였다. 생각의 흐름 - 일단 2중 포문으로는 잘 구현되는지 보자. 이중포문을 구현했지만 역시나 시간 이슈가 생겼다. 생각의 흐름 - 양쪽에서 줄여나가자. 늘 그렇듯, 이런 ..

Algorithm 2022.07.02