본문 바로가기

전체 글

[Leetcode/파이썬] 56. Merge Intervals Merge IntervalsGiven an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. Example 1:Input: intervals = [[1,3],[2,6],[8,10],[15,18]]Output: [[1,6],[8,10],[15,18]]Explanation: Since intervals [1,3] and [2,6] overlap, merge them into [1,6].Example 2:Input: intervals.. 더보기
[Leetcode/파이썬] 49. Group Anagrams Group AnagramsGiven an array of strings strs, group the anagrams together. You can return the answer in any order. Example 1:Input: strs = ["eat","tea","tan","ate","nat","bat"]Output: [["bat"],["nat","tan"],["ate","eat","tea"]]Explanation:There is no string in strs that can be rearranged to form "bat".The strings "nat" and "tan" are anagrams as they can be rearranged to form each other.The strin.. 더보기
[Leetcode/파이썬] 228.Summary Ranges Summary RangesYou are given a sorted unique integer array nums.A range [a,b] is the set of all integers from a to b (inclusive).Return the smallest sorted list of ranges that cover all the numbers in the array exactly. That is, each element of nums is covered by exactly one of the ranges, and there is no integer x such that x is in one of the ranges but not in nums.Each range [a,b] in the list s.. 더보기
[Leetcode/파이썬] 69. Sqrt(x) Sqrt(x)Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well.You must not use any built-in exponent function or operator.For example, do not use pow(x, 0.5) in c++ or x ** 0.5 in python. Example 1:Input: x = 4Output: 2Explanation: The square root of 4 is 2, so we return 2.Example 2:Input: x = 8Output: .. 더보기
[Leetcode/파이썬] 918. Maximum Sum Circular Subarray Maximum Sum Circular SubarrayGiven a circular integer array nums of length n, return the maximum possible sum of a non-empty subarray of nums.A circular array means the end of the array connects to the beginning of the array. Formally, the next element of nums[i] is nums[(i + 1) % n] and the previous element of nums[i] is nums[(i - 1 + n) % n].A subarray may only include each element of the fixe.. 더보기
[Leetcode/파이썬] 22. Generate Parentheses Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example 1:Input: n = 3Output: ["((()))","(()())","(())()","()(())","()()()"]Example 2:Input: n = 1Output: ["()"] Constraints:1 class Solution: def generateParenthesis(self, n: int) -> List[str]: def dfs(left, right, s) : if len(s) == n * 2 : .. 더보기
[Leetcode/파이썬] 136. Single Number Single NumberGiven a non-empty array of integers nums, every element appears twice except for one. Find that single one.You must implement a solution with a linear runtime complexity and use only constant extra space. Example 1:Input: nums = [2,2,1]Output: 1Example 2:Input: nums = [4,1,2,1,2]Output: 4Example 3:Input: nums = [1]Output: 1 Constraints:1 4-3 * 104 4Each element in the array appears .. 더보기
[Leetcode/파이썬] 53. Maximum Subarray Maximum SubarrayGiven an integer array nums, find the subarray with the largest sum, and return its sum. Example 1:Input: nums = [-2,1,-3,4,-1,2,1,-5,4]Output: 6Explanation: The subarray [4,-1,2,1] has the largest sum 6.Example 2:Input: nums = [1]Output: 1Explanation: The subarray [1] has the largest sum 1.Example 3:Input: nums = [5,4,-1,7,8]Output: 23Explanation: The subarray [5,4,-1,7,8] has t.. 더보기