two pointer(5)
-
[Leetcode] 1498. Number of Subsequences That Satisfy the Given Sum Condition
🗓️ Daily LeetCoding Challenge May, Day 6 class Solution: def numSubseq(self, nums: List[int], target: int) -> int: answer = 0 nums.sort() # O(NlogN) left, right = 0, len(nums) - 1 while left
2023.05.06 -
[Leetcode] 986. Interval List Intersections
class Solution: def intervalIntersection(self, firstList: List[List[int]], secondList: List[List[int]]) -> List[List[int]]: answer = [] i, j = 0, 0 if len(firstList) == 0 or len(secondList) == 0: return [] while i < len(firstList) and j < len(secondList): if firstList[i][1] < secondList[j][0]: i += 1 elif secondList[j][1] < firstList[i][0]: j += 1 else: intersection_start = max(firstList[i][0], ..
2023.05.05 -
[Leetcode] 844. Backspace String Compare
class Solution: def backspaceCompare(self, s: str, t: str) -> bool: def check(string): lst = [] for s in string: if s != "#": lst.append(s) else: if lst: lst.pop() return lst return check(s) == check(t)
2023.05.05 -
[Leetcode] 82. Remove Duplicates from Sorted List II
Solution 1. memoization class Solution: def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]: memo = {} newhead = ListNode(0) cur = newhead while head: if head.val not in memo: memo[head.val] = 1 cur.next = ListNode(head.val) cur = cur.next else: memo[head.val] += 1 head = head.next lst = [k for k, v in memo.items() if v == 1] newhead = ListNode(0) cur = newhead for i in ls..
2023.05.04 -
[Leetcode] 11. Container With Most Water
class Solution: def maxArea(self, height: List[int]) -> int: left, right = 0, len(height)-1 result = 0 while left
2023.04.27