Loading...

[Python] Leetcode - Top K Frequent Elements

https://leetcode.com/problems/top-k-frequent-elements/ Top K Frequent Elements - 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 # 문제해설: nums 배열과 k가 주어졌을때, nums배열에서 가장 자주 등장하는 k개의 수를 return해라. (순서는 상관없다) # heap을 사용해서 푸는 간단한 문제이다. # defaultdict을 사용해 cnt에 nums의 숫자들의 갯수를 저장해준다. (Count..

[Python] LeetCode - Decode Ways

https://leetcode.com/problems/decode-ways Decode Ways - 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 -> 'A', 2 -> 'B', 3 -> 'C' ... 26 -> 'Z' 이런식으로 디코딩을 할 수 있다. Incoding된 문자열을 Decoding하려면 모든 숫자를 '그룹화'한 다음 다시 문자로 mapping 해야한다. ex) "11106"을 mapping하는 경우 "AAJF" with the g..

[Python] LeetCode - Coin Change

https://leetcode.com/problems/coin-change/ Coin Change - 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 * 문제해석: 주어진 coins배열의 동전들을 가지고 amount에 해당하는 값을 만들 때, 필요한 동전의 최소 갯수를 return, 만들 수 없으면 -1 return # DP문제이다. Greedy문제인 '거스름돈 문제'와 비슷해 보이지만, 이 문제는 coins의 동전들이 다른 동전의 배수가 아닐 수 있으므로(배수인..

[Python] LeetCode - Restore IP Addresses

https://leetcode.com/problems/restore-ip-addresses/ Restore IP Addresses - 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 restoreIpAddresses(self, s: str) -> List[str]: if len(s) < 4: return [] answer = [] IPs = ..

[Python] Leetcode - Combination Sum

https://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 # 요즘 연습하고 있는 백트래킹 문제이다. candidates의 수들 중 합이 target인 배열을 return하는 문제이다. # 6번째 줄에서 comb를 바로 append하면 안되고, comb.copy()를 append해줘야 answer에 값이 제대로 들어간다. class Solution: def c..

[Python] LeetCode - Letter Combinations of a Phone Number

https://leetcode.com/problems/letter-combinations-of-a-phone-number/ Letter Combinations of a Phone 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 # 외국 문제풀이 사이트인 LeetCode문제이다. 영어문제를 해석하면서 풀어야해서 영어실력 증진에도 도움이 되는 것 같다. # '백트래킹' 기초를 연습하기 위해 푼 문제이다. # class와 letterCombination..