Skip to content

Instantly share code, notes, and snippets.

# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def largestValues(self, root: TreeNode) -> List[int]:
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def oddEvenList(self, head: ListNode) -> ListNode:
oddDummy = ListNode(0)
oddNode = oddDummy
class Solution:
def minRemoveToMakeValid(self, s: str) -> str:
validParenthese = 0
leftCount = 0
for val in s:
if val == "(":
leftCount += 1
elif val == ")" and leftCount > 0:
leftCount -= 1
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
head = ListNode(0)
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:
class Solution:
def twoCitySchedCost(self, costs: List[List[int]]) -> int:
res = []
bSum = 0
for cost in costs:
res.append(cost[1] - cost[0])
bSum += cost[1]
res.sort()
# print(res)
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
return min(text.count("b"), text.count("a"),
text.count("l") //2, text.count("o") // 2, text.count("n"))
class Solution:
def maxNumberOfBalloons(self, text: str) -> int:
bCount = 0
aCount = 0
lCount = 0
oCount = 0
nCount = 0
for ch in text:
if ch == "b":
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
if len(s) != len(t): return False
for ch in s:
if s.count(ch) != t.count(ch):
return False
return True
class Solution:
def isAnagram(self, s: str, t: str) -> bool:
sList = list(set(list(s)))
tList = list(set(list(t)))
if len(sList) != len(tList): return False
for ch in sList:
# print(sList.count(ch), tList.count(ch))