파이썬 코딩테스트 24

[Python] 리트코드 140. Word Break II

https://leetcode.com/problems/word-break-ii/ Word Break II - 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 class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> List[str]: def isInDict(start, words): # 4. 3에서 end+1하기 땜에 시작위치가 len(s)라면 정상적으로 찾은거 if start == len(s): a..

알고리즘 2022.01.10

[Python] 리트코드 139. Word Break

https://leetcode.com/problems/word-break/ Word Break - 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 class Solution: def wordBreak(self, s: str, wordDict: List[str]) -> bool: @lru_cache(None) # 결과 캐싱 def isInDict(start): # 4. 3번에서 재귀돌렸을때 현재문자열위치+1을 보내니까 # 그걸 시작위치로 받았을 때 그게 전체 문자열..

알고리즘 2022.01.10

[Python] 리트코드 491. Increasing Subsequences

https://leetcode.com/problems/increasing-subsequences/ Increasing Subsequences - 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 이 문제는 예전에 풀었던 문제와 방식이 비슷했다. https://leetcode.com/problems/letter-tile-possibilities/ Letter Tile Possibilities - LeetCode Level up your coding skills and..

알고리즘 2022.01.03

[Python] 리트코드 763. Partition Labels(Hash)

https://leetcode.com/problems/partition-labels/ Partition Labels - 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 문제의 첫 번째 예시에서(ababcbacadefegdehijhklij) 제일 처음 알파벳인 a를 자르려면 최소 [8]까지는 한 파트로 묶어 잘라야 나머지 파트에 a가 포함되지 않는다. 그렇게 0~8까지를 한 파트로 묶으면 그 안의 알파벳들 중 나머지 부분에 포함되는 알파벳은 하나도 없다. 그러니 이..

알고리즘 2021.12.31

[Python] 리트코드 313. Super Ugly Number(Hash)

https://leetcode.com/problems/super-ugly-number/ Super Ugly Number - 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 이 문제는 예전에 풀었던 264. Ugly Number II (https://leetcode.com/problems/ugly-number-ii/) 이 문제와 비슷하다. 그래서 그 문제를 응용해서 풀어보았다. 결국 primes factors를 구하는 문제인건데 주어지는 primes에 있는 숫자들로..

알고리즘 2021.12.31

[Python] 리트코드 583. Delete Operation for Two Strings

https://leetcode.com/problems/delete-operation-for-two-strings/ Delete Operation for Two Strings - 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 먼저 word1이랑 word2에서 공통된 알파벳들을 알아낸다. 공통되지 않은 알파벳들은 조작되어야 하는 알파벳이므로 word1과 word2의 각 length를 비교해 그 차이만큼 답으로 리턴한다. 공통된 알파벳을 가려내는데 고려해야 하는 사항..

알고리즘 2021.12.02

[Python] 리트코드 309. Best Time to Buy and Sell Stock with Cooldown

https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/ Best Time to Buy and Sell Stock with Cooldown - 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 이 문제는 [121. Best Time to Buy and Sell Stock] 이랑 [122. Best Time to Buy and Sell Stock II] 의 다음 단계라고 할 수 있다. 이..

알고리즘 2021.10.27

[Python] 리트코드 1014. Best Sightseeing Pair

https://leetcode.com/problems/best-sightseeing-pair/ Best Sightseeing Pair - 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 values[i] + values[j] + i - j 를 계산했을 때 최댓값을 구하는 문제이다. values[i] + values[j] + i - j 값이 최대가 되려면 values[i] + i는 최대가 되어야 하고 values[j] - j도 최대가 되어야 한다. values의 임..

알고리즘 2021.10.26

[Python] 리트코드 1567. Maximum Length of Subarray With Positive Product (누적 곱셈)

https://leetcode.com/problems/maximum-length-of-subarray-with-positive-product/ Maximum Length of Subarray With Positive Product - 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 이 문제는 https://leetcode.com/problems/maximum-product-subarray/ 문제의 응용 버전이다. Maximum Product Subarray는 su..

알고리즘 2021.10.25