LC475 Heaters

class Solution: def findRadius(self, houses: List[int], heaters: List[int]) -> int: # time O(N*M) spaceO(1) # main idea: create two extreme heaters at two end, record each house's min neighbour distance, and get the max heaters.sort() houses.sort() heaters = [float('-inf')] + heaters+[float('inf')] res, idx = 0,0 for house in houses: while... [Read More]

LC520 Detect Capital

link ```python main idea, compare based on case time O(O) spaceO(1) class Solution: def detectCapitalUse(self, word: str) -> bool: up = string.ascii_uppercase low = string.ascii_lowercase def helper(word,standard): for each in word: if each not in standard: return False return True if word[0] in low and word[-1] in low: return helper(word,low)... [Read More]
Tags: LinkedList

LC876 Middle of the Linked List

link ```python class MinStack: main idea: use two stacks to store 1:regular pushed elements 2: record min vals def __init__(self): """ initialize your data structure here. """ self.stack = [] self.minStack = [] [Read More]
Tags: LinkedList

LC876 Middle of the Linked List

link # 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) # main idea: fast slow pointer def middleNode(self, head: ListNode) -> ListNode: slow = fast = head while fast and fast.next:... [Read More]
Tags: LinkedList