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 findMatrix(self, nums: List[int]) -> List[List[int]]: | |
| ans = [set()] | |
| # m {n:cur_index} | |
| m = {} | |
| for n in nums: | |
| m[n] = m.get(n, -1) + 1 | |
| if m[n] + 1 > len(ans): | |
| ans.append(set()) | |
| ans[-1].add(n) |
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 smallestNumber(self, num: int) -> int: | |
| sign = 1 | |
| if num < 0: | |
| sign = -1 | |
| num = num * -1 | |
| ans = [int(c) for c in str(num)] | |
| ans.sort() | |
| if sign == -1: |
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 isValidSudoku(self, board: List[List[str]]) -> bool: | |
| hor = [set() for i in range(9)] | |
| ver = [set() for j in range(9)] | |
| boxes = [[set() for j in range(3)] for i in range(3)] | |
| for i in range(9): | |
| for j in range(9): | |
| num = board[i][j] | |
| if num in '123456789': |
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 increasingTriplet(self, nums: List[int]) -> bool: | |
| first = second = float('inf') | |
| for n in nums: | |
| if n <= first: | |
| first = n | |
| elif n <= second: | |
| second = n | |
| else: |
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 sortEvenOdd(self, nums: List[int]) -> List[int]: | |
| even = [] | |
| odd = [] | |
| for i in range(len(nums)): | |
| if i % 2 == 0: | |
| even.append(nums[i]) | |
| else: | |
| odd.append(nums[i]) |
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 removeDuplicates(self, nums: List[int]) -> int: | |
| k = 0 | |
| for i in range(len(nums)): | |
| if nums[i] > nums[k]: | |
| k += 1 | |
| nums[k] = nums[i] | |
| return k + 1 |
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 validPalindrome(self, s: str) -> bool: | |
| def isPalindrome(l, r) -> bool: | |
| while l < r: | |
| if s[l] != s[r]: | |
| return False | |
| l += 1 | |
| r -= 1 | |
| return True |
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 findNumbers(self, nums: List[int]) -> int: | |
| def countDigits(num:int) -> int: | |
| ans = 1 | |
| while num > 9: | |
| num = num // 10 | |
| ans += 1 | |
| return ans | |
| res = 0 | |
| for n in 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 findMaxConsecutiveOnes(self, nums: List[int]) -> int: | |
| maxL = 0 | |
| cur = 0 | |
| for n in nums: | |
| if n == 1: | |
| cur += 1 | |
| maxL = max(maxL, cur) | |
| else: |
NewerOlder