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 mergeTriplets(self, triplets: List[List[int]], target: List[int]) -> bool: | |
| mask = 0 | |
| for t in triplets: | |
| if all(t[i] <= target[i] for i in range(3)): | |
| for i in range(3): | |
| if t[i] == target[i]: | |
| mask |= (1 << 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 isNStraightHand(self, hand: List[int], groupSize: int) -> bool: | |
| if len(hand) % groupSize: | |
| return False | |
| count = {} | |
| for n in hand: | |
| count[n] = 1 + count.get(n, 0) | |
| minHeap = list(count.keys()) |
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 canCompleteCircuit(self, gas: List[int], cost: List[int]) -> int: | |
| if sum(gas) < sum(cost): | |
| return -1 | |
| total_tank = 0 | |
| start_index = 0 | |
| for i in range(len(gas)): | |
| total_tank += gas[i] - cost[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 jump(self, nums: List[int]) -> int: | |
| jumps = 0 | |
| current_jump_end = 0 | |
| farthest_reach = 0 | |
| for i in range(len(nums) - 1): | |
| farthest_reach = max(farthest_reach, nums[i] + i) | |
| if i == current_jump_end: |
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 canJump(self, nums: List[int]) -> bool: | |
| goal = len(nums) - 1 | |
| for i in range(len(nums) - 1, -1, -1): | |
| if nums[i] + i >= goal: | |
| goal = i | |
| return True if goal == 0 else 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 maxSubArray(self, nums: List[int]) -> int: | |
| max_sum, curr_sum = nums[0], nums[0] | |
| for num in nums[1:]: | |
| curr_sum = max(num, curr_sum + num) | |
| max_sum = max(max_sum, curr_sum) | |
| return max_sum |
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 minInterval(self, intervals: List[List[int]], queries: List[int]) -> List[int]: | |
| intervals.sort() | |
| sorted_queries = sorted([(q, i) for i, q in enumerate(queries)]) | |
| minHeap = [] | |
| res = [0] * len(queries) | |
| i = 0 | |
| for q, original_idx in sorted_queries: |
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
| """ | |
| Definition of Interval: | |
| class Interval(object): | |
| def __init__(self, start, end): | |
| self.start = start | |
| self.end = end | |
| """ | |
| class Solution: | |
| def minMeetingRooms(self, intervals: List[Interval]) -> int: |
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
| """ | |
| Definition of Interval: | |
| class Interval(object): | |
| def __init__(self, start, end): | |
| self.start = start | |
| self.end = end | |
| """ | |
| class Solution: | |
| def canAttendMeetings(self, intervals: List[Interval]) -> bool: |
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 eraseOverlapIntervals(self, intervals: List[List[int]]) -> int: | |
| res = 0 | |
| intervals.sort(key = lambda interval: interval[0]) | |
| prev = intervals[0] | |
| for start, end in intervals[1:]: | |
| if start < prev[1]: | |
| res += 1 | |
| prev[1] = min(prev[1], end) |
NewerOlder