Skip to content

Instantly share code, notes, and snippets.

View parcar's full-sized avatar

Parris parcar

View GitHub Profile
class Solution(object):
def canWinNim(self, n):
"""
:type n: int
:rtype: bool
"""
return n % 4
'''
Runtime: 8 ms, faster than 96.34% of Python online submissions for Nim Game.
Memory Usage: 11.5 MB, less than 100.00% of Python online submissions for Nim Game.
class Solution:
def maxArea(self, height: List[int]) -> int:
lo = 0
hi = len(height)-1
cmax = 0
while(lo < hi):
cmax = max(min(height[lo],height[hi]) * (hi - lo), cmax)
if (height[lo] > height[hi]):
hi -= 1
class Solution:
def maxProfit(self, prices: List[int]) -> int:
price = []
cmax = 0
for i in prices[::-1]:
cmax = i if i > cmax else cmax
price.append(cmax)
cmax = 0
class Solution:
def longestPalindrome(self, s: str) -> int:
ms = set()
count = 0
for i in s:
if i in ms:
ms.discard(i)
count += 2
class Solution(object):
def findComplement(self, num):
"""
:type num: int
:rtype: int
"""
binary = [int(i) ^ 1 for i in bin(num)[2:]]
return int("".join(map(str,binary)),2)
'''
Runtime: 12 ms, faster than 89.42% of Python online submissions for Number Complement.
class Solution(object):
def removeDuplicates(self, S):
"""
:type S: str
:rtype: str
"""
if not len(S):
return S
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def bstToGst(self, root):
"""
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def insertIntoBST(self, root, val):
"""
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def searchBST(self, root, val):
"""
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
'''
Intuition: