Skip to content

Commit da98fa4

Browse files
committed
week1 solutions
1 parent 9028c5c commit da98fa4

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
"""
22
https://leetcode.com/problems/best-time-to-buy-and-sell-stock/
33
"""
4+
5+
6+
class Solution:
7+
def maxProfit(self, prices: List[int]) -> int:
8+
max_profit = 0
9+
min_price = prices[0]
10+
11+
for price in prices:
12+
profit = price - min_price
13+
min_price = min(min_price, price)
14+
max_profit = max(profit, max_profit)
15+
16+
return max_profit

contains-duplicate/Bumsu-Yi.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
"""
22
https://leetcode.com/problems/contains-duplicate/
33
"""
4+
5+
6+
class Solution:
7+
def containsDuplicate(self, nums: List[int]) -> bool:
8+
my_dict = {}
9+
10+
for num in nums:
11+
if num in my_dict:
12+
return True
13+
my_dict[num] = 0
14+
15+
return False

valid-palindrome/Bumsu-Yi.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
11
"""
22
https://leetcode.com/problems/valid-palindrome/
33
"""
4+
5+
6+
class Solution:
7+
def isPalindrome(self, s: str) -> bool:
8+
alphanumeric_chars = []
9+
for char in s:
10+
if char.isalnum():
11+
lowercase_letter = char.lower()
12+
alphanumeric_chars.append(lowercase_letter)
13+
14+
return alphanumeric_chars == alphanumeric_chars[::-1]

0 commit comments

Comments
 (0)