This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def topKFrequent(self, nums: List[int], k: int) -> List[int]: | |
| # lets use the bucket sort | |
| # dict | |
| # count: [0, 1, 2, 3] | |
| # freq: [[], [3], [2], [1]] | |
| # basically values how many time have appeared | |
| # (index is count) | |
| n = len(nums) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def longestConsecutive(self, nums: List[int]) -> int: | |
| s = set(nums) | |
| longest = 0 | |
| for num in s: | |
| if num - 1 not in s: | |
| next_num = num + 1 | |
| length = 1 | |
| while next_num in s: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def maxArea(self, height): | |
| """ | |
| :type height: List[int] | |
| :rtype: int | |
| """ | |
| left, right = 0, len(height) - 1 | |
| maxArea = 0 | |
| while left < right: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def threeSum(self, nums): | |
| nums.sort() | |
| res = [] | |
| for i in range(len(nums) - 2): | |
| if i > 0 and nums[i] == nums[i-1]: # skip duplicate i | |
| continue | |
| low, high = i + 1, len(nums) - 1 | |
| while low < high: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution(object): | |
| def isValid(self, s): | |
| """ | |
| :type s: str | |
| :rtype: bool | |
| """ | |
| stack = [] | |
| closeToOpen = { |
OlderNewer