알고리즘/알고리즘 문제 복기
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의 값을 이용해보기로 했고 다음과 같이 풀어냈다.