본문 바로가기
반응형

{ Problem Solving }/리트코드44

[ 리트코드 leetcode] 70. Climbing Stairs 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 이 문제는 사실 피보나치 수열과 같은 문제다. n번째 계단에 도착을 하려면 그 이전 시점에는 n-1번째 또는 n-2번째 계단에 위치해있을 것이다. 즉 f(n) = f(n-1) + f(n-2) 임을 알 수 있다. class Solution: def climbStairs(self, n: int) -> int: if n 2021. 4. 19.
[리트코드 leetcode] 53. Maximum Subarray 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 class Solution: def maxSubArray(self, nums: List[int]) -> int: maximum= -sys.maxsize sum=0 for num in nums: sum+=num maximum = max(maximum, sum) if sum < 0 and num 2021. 4. 19.
[리트코드 leetcode] 241. Different Ways to Add Parentheses leetcode.com/problems/different-ways-to-add-parentheses/ Different Ways to Add Parentheses - 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 diffWaysToCompute(self, expression: str) -> List[int]: values = [] def compute(left,right,op): for l in left: for r in ri.. 2021. 4. 19.
[리트코드 leetcode] 621. Task Scheduler leetcode.com/problems/task-scheduler/ Task Scheduler - 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시간 고생해서 heap으로 풀어냈다. 하지만 너무 1차원적인 풀이라서 시간이 매우 오래 걸렸다.. class Solution: def leastInterval(self, tasks: List[str], n: int) -> int: wait = {} for task in tasks: wait[task]=0 counter.. 2021. 4. 17.
[리트코드 leetcode] 147. Insertion Sort List leetcode.com/problems/insertion-sort-list/ Insertion Sort 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 풀긴 하였지만 소요 시간이 매우 길다.. # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution:.. 2021. 4. 14.
[리드코드 leetcode] 56. Merge Intervals leetcode.com/problems/merge-intervals/ Merge Intervals - 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 merge(self, intervals: List[List[int]]) -> List[List[int]]: intervals.sort(key = lambda x: x[0]) result = [] temp = intervals[0] for i .. 2021. 4. 14.
반응형