Skip to content

Instantly share code, notes, and snippets.

@bloopepper
bloopepper / Train007_1.py
Last active November 25, 2020 13:31
1475. Final Prices With a Special Discount in a Shop
class Solution(object):
def finalPrices(self, prices):
"""
:type prices: List[int]
:rtype: List[int]
"""
# reference : huahua :https://youtu.be/X98Yc4YtgyA
# Monotonic Stack
stack = []
for i, v in enumerate(prices):
@bloopepper
bloopepper / Train007_2.py
Created November 23, 2020 13:43
1642. Furthest Building You Can Reach
class Solution(object):
def furthestBuilding(self, heights, bricks, ladders):
"""
:type heights: List[int]
:type bricks: int
:type ladders: int
:rtype: int
"""
@bloopepper
bloopepper / Train006_2.py
Created November 17, 2020 15:27
393. UTF-8 Validation
class Solution(object):
def validUtf8(self, data):
"""
:type data: List[int]
:rtype: bool
"""
@bloopepper
bloopepper / Train006_1.py
Last active November 18, 2020 14:15
392. Is Subsequence
class Solution(object):
def isSubsequence(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
# Power of iteration:iter()
# The all() method returns True when all elements in the given iterable are true. If not, it returns False.
# s is subsequence of t.
@bloopepper
bloopepper / Train005_2.py
Last active November 16, 2020 14:51
390. Elimination Game
class Solution(object):
def lastRemaining(self, n):
"""
:type n: int
:rtype: int
"""
#此題目為遞迴題目
@bloopepper
bloopepper / Train005_1.py
Last active November 16, 2020 14:22
389. Find the Difference
class Solution(object):
def findTheDifference(self, s, t):
"""
:type s: str
:type t: str
:rtype: str
"""
ans = 0
for c in s+t:
ans = ord(c) # function ord is for character to transfer into unicode
@bloopepper
bloopepper / Train004-2.py
Last active November 12, 2020 14:39
1630. Arithmetic Subarrays
class Solution(object):
def checkArithmeticSubarrays(self, nums, l, r):
"""
:type nums: List[int]
:type l: List[int]
:type r: List[int]
:rtype: List[bool]
"""
# define a def to do arith check
# aware the duplicate element use "set"
@bloopepper
bloopepper / Train004-1.py
Last active November 12, 2020 13:53
1626. Best Team With No Conflicts
class Solution(object):
def bestTeamScore(self, scores, ages):
"""
:type scores: List[int]
:type ages: List[int]
:rtype: int
"""
# sort and combine into a 2-d array
# longest increasing subarray
# use for loop to search the team member and sum up to the highest overall score
@bloopepper
bloopepper / Train003-1.py
Created November 11, 2020 14:24
1624. Largest Substring Between Two Equal Characters
class Solution(object):
def maxLengthBetweenEqualCharacters(self, s):
"""
:type s: str
:rtype: int
"""
n = len(s)
strdist = -1
if n in (0,1) :
@bloopepper
bloopepper / Weekly Contest 212_1.py
Last active November 5, 2020 13:36
[Leetcode] Training day-002
# Exapmple: releaseTimes = [12,23,36,46,62]
# keysPressed = "spuda"
class Solution(object):
def slowestKey(self, releaseTimes, keysPressed):
"""
:type releaseTimes: List[int]
:type keysPressed: str
:rtype: str
"""
n = len(releaseTimes)