File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed
best-time-to-buy-and-sell-stock Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 11"""
22https://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
Original file line number Diff line number Diff line change 11"""
22https://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
Original file line number Diff line number Diff line change 11"""
22https://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 ]
You can’t perform that action at this time.
0 commit comments