```python
class Solution:
def findPoisonedDuration(self, timeSeries: List[int], duration: int) -> int:
size = len(timeSeries)
if size == 0:
return 0
res = 0
for i in range(size-1):
res += min(timeSeries[i+1] - timeSeries[i],duration)
return res + duration
[Read More]
LC179 Largest Number
#main idea: change the default implementation for comparison and sort in descending order. class Solution: def largestNumber(self, nums: List[int]) -> str: # time O(NlgN) space O(N) comp = lambda a,b:1 if a+b > b+a else -1 if a+b < b+a else 0 _nums = list(map(str,nums)) # here add a list()...
[Read More]
LC125 Valid Palindrome
class Solution: """ main idea: to strip space and check each char if they are alphabetic or numeric, if not, skip and save it into res (initialize with empyt string), and compare from beginning and end time O(N) space O(N) """ def isPalindrome(self, s: str) -> bool: res = ''...
[Read More]
LC389 Find the Difference
naive solution: using hash table. since diff between s and t is one char only, first count time of char in s, then decrement char according to t, if char is out of count range or never shown in hashtable, return that char ```python class Solution: def findTheDifference(self, s: str,...
[Read More]
LC2 Add Two Numbers
# Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # self.next = next class Solution: # time O(N) space O(1) def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: carry = 0 # create dummy node and a pointer, point at dummy node,...
[Read More]