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 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]: | |
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 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 |
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 minRemoveToMakeValid(self, s: str) -> str: | |
validParenthese = 0 | |
leftCount = 0 | |
for val in s: | |
if val == "(": | |
leftCount += 1 | |
elif val == ")" and leftCount > 0: | |
leftCount -= 1 |
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 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) |
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 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: | |
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 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) |
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 maxNumberOfBalloons(self, text: str) -> int: | |
return min(text.count("b"), text.count("a"), | |
text.count("l") //2, text.count("o") // 2, text.count("n")) |
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 maxNumberOfBalloons(self, text: str) -> int: | |
bCount = 0 | |
aCount = 0 | |
lCount = 0 | |
oCount = 0 | |
nCount = 0 | |
for ch in text: | |
if ch == "b": |
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 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 |
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 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)) |
NewerOlder