리트코드
-
[🥰 leetcode] 692. Top K Frequent WordsAlgorithm/1일 1코테 2022. 10. 19. 12:51
https://leetcode.com/problems/top-k-frequent-words/ Top K Frequent Words - 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 리스트 안에 가장 많이 존재하는 단어순 && 갯수가 같은 경우엔 사전순 정렬을 기준으로 k개를 뽑아내는 문제 나의 풀이 class Solution: def topKFrequent(self, words: List[str], k: int) -> List[str]: # 중복없는 set 생성..
-
[🥰 leetcode] 1328. Break a PalindromeAlgorithm/1일 1코테 2022. 10. 18. 11:28
https://leetcode.com/problems/break-a-palindrome/ Break a Palindrome - 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 팰린드롬 문자열을 단 한가지의 문자만 바꾸어 팰린드롬이 아니면서 && 사전식 순서에서 가장 작은 값으로 만드는 문제 예를 들어 abccba => aaccba 나의 풀이 class Solution: def breakPalindrome(self, palindrome: str) -> str: # ..
-
[🥰 leetcode] 53. Maximum SubarrayAlgorithm/1일 1코테 2022. 10. 14. 21:39
https://leetcode.com/problems/maximum-subarray/ Maximum Subarray - 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 최댓값이 될 수 있는 연속 서브 배열을 찾아라! 나의 풀이 def maxSubArray(self, nums: List[int]) -> int: dp = [0 for _ in range(len(nums))] for i, n in enumerate(nums): # 맨 처음 값이 경우 값 넣고 끝~!~~..
-
[😭 leetcode] 976. Largest Perimeter TriangleAlgorithm/1일 1코테 2022. 10. 12. 11:57
https://leetcode.com/problems/largest-perimeter-triangle/ Largest Perimeter Triangle - 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 삼각형의 세 변의 길이 합 중 가장 큰 값을 찾는 문제 easy라며... easy라며...!!!! 나의 시도... import itertools class Solution: def largestPerimeter(self, nums: List[int]) -> int..
-
[😭 leetcode] 334. Increasing Triplet SubsequenceAlgorithm/1일 1코테 2022. 10. 11. 20:13
문제 https://leetcode.com/problems/increasing-triplet-subsequence/ Increasing Triplet Subsequence - 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 증가하는 시퀀스가 3개인 경우를 찾는 문제 # [1,2,3,4,5] => 1,2,3 TRUE # [5,4,3,2,1] => 증가하는 시퀀스가 존재하지 않음. FALSE # [2,1,5,0,4,6] => 0,4,6 TRUE 나의 (시도했으나 장렬..
-
[😭 leetcode] 15. 3SumAlgorithm/1일 1코테 2022. 7. 25. 20:48
리트코드 13번째 문제 [3Sum] https://leetcode.com/problems/3sum/ 3Sum - 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 문제 배열을 입력받아 합으로 0을 만들 수 있는 3개의 엘리먼트를 출력하라 (중복X) 정답 class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: result = [] # 편의상 정렬 수행 nums.sort() # i를 기준으로 투 ..
-
[leetcode] 78. subsets (python)Algorithm/1일 1코테 2021. 8. 19. 13:51
리트코드 78번 문제 https://leetcode.com/problems/subsets/submissions/ Subsets - 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 subsets(self, nums: List[int]) -> List[List[int]]: answer = [[]] # 빈 값을 미리 넣어줌 for i in range(1, len(nums)+1): number_group = list(it..
-
[leetcode] 그리디 알고리즘 모음집.zipAlgorithm/1일 1코테 2021. 8. 14. 21:51
그리기 알고리즘의 핵심은 그때그때 가장 적합한 선택을 하는 것! 122번. 주식 팔고사기 가장 적합한 선택 -> 바로 다음 값이 오르면 팔고, 아니면 만다! class Solution: def maxProfit(self, prices: List[int]) -> int: result = 0 # 결과 저장 for i in range(len(prices)-1): if prices[i+1]>prices[i]: # 다음 값이 크면 판다! result += prices[i+1]-prices[i] return result 406번. 키에 따라 재정렬 가장 적합한 선택 -> 키(역순)/인덱스 순으로 정렬한 뒤 인덱스대로 삽입 class Solution: def reconstructQueue(self, people: L..