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 merge(self, intervals: List[List[int]]) -> List[List[int]]: | |
| intervals.sort() | |
| ans = [] | |
| for i in range(len(intervals) - 1): | |
| if intervals[i][1] >= intervals[i+1][1]: | |
| intervals[i+1] = intervals[i] | |
| elif intervals[i][1] >= intervals[i+1][0]: |
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 countDays(self, days: int, meetings: List[List[int]]) -> int: | |
| size = len(meetings) | |
| meetings.sort() | |
| cur = 0 | |
| for i in range(size - 1): | |
| if meetings[i][1] >= meetings[i+1][1]: | |
| meetings[i+1] = meetings[i] | |
| elif meetings[i][1] >= meetings[i+1][0]: |
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 carPooling(self, trips: List[List[int]], capacity: int) -> bool: | |
| bus = [] | |
| for num, fr, to in trips: | |
| bus.append((fr, num)) | |
| bus.append((to, -num)) | |
| bus.sort() | |
| cur = 0 | |
| for loc, num in bus: |
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 fourSumCount(self, nums1: List[int], nums2: List[int], nums3: List[int], nums4: List[int]) -> int: | |
| m12 = {} | |
| size = len(nums1) | |
| for i in range(size): | |
| for j in range(size): | |
| m12[nums1[i]+nums2[j]] = m12.get(nums1[i]+nums2[j], 0) + 1 | |
| ans = 0 | |
| for k in range(size): | |
| for l in range(size): |
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 isAnagram(self, s: str, t: str) -> bool: | |
| m = {} | |
| for c in s: | |
| m[c] = m.get(c, 0) + 1 | |
| for c in t: | |
| if c not in m: | |
| return False | |
| 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 isIsomorphic(self, s: str, t: str) -> bool: | |
| mSTot = {} | |
| mTTos = {} | |
| for i in range(len(s)): | |
| cs = s[i] | |
| ct = t[i] | |
| if (cs not in mSTot and ct in mTTos) or (cs in mSTot and ct not in mTTos): | |
| return False |
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 arithmeticTriplets(self, nums: List[int], diff: int) -> int: | |
| s = set(nums) | |
| ans = 0 | |
| for n in nums: | |
| if n + diff in s and n + 2 * diff in s: | |
| ans += 1 | |
| return ans |
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 containsNearbyDuplicate(self, nums: List[int], k: int) -> bool: | |
| idx = {} | |
| for i in range(len(nums)): | |
| if nums[i] in idx: | |
| curI = idx[nums[i]] | |
| if i - curI <= k: | |
| return True | |
| idx[nums[i]] = 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 intersect(self, nums1: List[int], nums2: List[int]) -> List[int]: | |
| s1 = set(nums1) | |
| s2 = set(nums2) | |
| intsec = s1 & s2 | |
| map1 = {} | |
| map2 = {} | |
| for n in nums1: | |
| map1[n] = map1.get(n, 0) + 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 findNthDigit(self, n: int) -> int: | |
| if n < 9: | |
| return n | |
| i = 1 | |
| while n > 9 * (10 ** (i - 1)) * i: | |
| n -= 9 * (10 ** (i - 1)) * i | |
| i += 1 |
NewerOlder