This file contains 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(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): |
This file contains 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(object): | |
def furthestBuilding(self, heights, bricks, ladders): | |
""" | |
:type heights: List[int] | |
:type bricks: int | |
:type ladders: int | |
:rtype: int | |
""" | |
This file contains 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(object): | |
def validUtf8(self, data): | |
""" | |
:type data: List[int] | |
:rtype: bool | |
""" |
This file contains 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(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. |
This file contains 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(object): | |
def lastRemaining(self, n): | |
""" | |
:type n: int | |
:rtype: int | |
""" | |
#此題目為遞迴題目 |
This file contains 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(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 |
This file contains 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(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" |
This file contains 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(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 |
This file contains 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(object): | |
def maxLengthBetweenEqualCharacters(self, s): | |
""" | |
:type s: str | |
:rtype: int | |
""" | |
n = len(s) | |
strdist = -1 | |
if n in (0,1) : |
This file contains 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
# 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) |
NewerOlder