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 ListNode(object): | |
def __init__(self, val=0, next=None): | |
self.val = val | |
self.next = next | |
class Solution(object): | |
def reverse_list(self, head): | |
""" | |
:type head: ListNode |
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
from collections import deque | |
class MinStack(object): | |
def __init__(self): | |
self.items = deque() | |
def is_empty(self): | |
return not self.items |
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
from collections import deque | |
class TreeNode(object): | |
def __init__(self, val=0, left=None, right=None): | |
self.val = val | |
self.left = left | |
self.right = right | |
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 ListNode(object): | |
def __init__(self, val=0, next=None): | |
self.val = val | |
self.next = next | |
class Solution(object): | |
def merge_two_lists(self, list1, list2): | |
""" | |
:type list1: Optional[ListNode] |
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 max_profit(self, prices): | |
""" | |
:type prices: List[int] | |
:rtype: int | |
""" | |
left_index = 0 | |
right_index = 1 | |
max_profit = 0 |
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 max_area(self, height): | |
""" | |
:type height: List[int] | |
:rtype: int | |
""" | |
max_volume = 0 | |
left_pointer = 0 | |
right_pointer = len(height) - 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
def two_sum(self, nums, i, results): | |
left_pointer = i + 1 | |
right_pointer = len(nums) - 1 | |
while left_pointer < right_pointer: | |
total = nums[i] + nums[left_pointer] + nums[right_pointer] | |
if total > 0: | |
right_pointer -= 1 | |
elif total < 0: | |
left_pointer += 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
class Solution: | |
def two_sum(self, numbers, target): | |
""" | |
:type numbers: List[int] | |
:type target: int | |
:rtype: List[int] | |
""" | |
left_pointer = 0 | |
right_pointer = len(numbers) - 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
class Solution: | |
def is_alpha_num(self, c): | |
return ( | |
ord("A") <= ord(c) <= ord("Z") | |
or ord("a") <= ord(c) <= ord("z") | |
or ord("0") <= ord(c) <= ord("9") | |
) | |
def is_palindrome(self, s): | |
""" |
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
from collections import defaultdict | |
class Solution: | |
def group_anagrams(self, strs): | |
""" | |
:type strs: List[str] | |
:rtype: List[List[str]] | |
""" | |
result = defaultdict(list) |