This file contains hidden or 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
type Corporation { | |
name: String! | |
mountains: [Mountain!]! | |
} | |
type Mountain { | |
name: String! | |
lifts: [Lift!]! | |
trails: [Trail!]! | |
employees: [Employee!]! |
This file contains hidden or 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
# Definition for singly-linked list. | |
class ListNode: | |
def __init__(self, x): | |
self.val = x | |
self.next = None | |
class Solution: | |
def reverseList(self, head: ListNode) -> ListNode: | |
if head is None or head.next is None: | |
return head |
This file contains hidden or 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 numUniqueEmails(self, emails: List[str]) -> int: | |
uniques = set() | |
for email in emails: | |
uniques.add(parse_email(email)) | |
return len(uniques) | |
def parse_email(email: str) -> str: | |
first_half, second_half = email.split('@') |
This file contains hidden or 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 searchRange(self, nums: List[int], target: int) -> List[int]: | |
if len(nums) == 0: | |
return [-1, -1] | |
if len(nums) == 1: | |
if target == nums[0]: | |
return [0, 0] | |
def binary_search(left, right): | |
mid = math.floor((left + right) / 2) |
This file contains hidden or 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 strStr(self, haystack: str, needle: str) -> int: | |
if needle == "": | |
return 0 | |
if len(haystack) == 1 or len(haystack) == len(needle): | |
return 0 if haystack == needle else -1 | |
if len(needle) > len(haystack): | |
return -1 |
This file contains hidden or 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 searchInsert(self, nums: List[int], target: int) -> int: | |
if target < nums[0]: return 0 | |
elif target > nums[len(nums) - 1]: return len(nums) | |
def recurse(left, right): | |
if left >= right: | |
if nums[left] < target: return left + 1 | |
elif nums[right] < target: return right + 1 | |
return right |
This file contains hidden or 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 lengthOfLongestSubstring(self, s): | |
""" | |
:type s: str | |
:rtype: int | |
""" | |
if len(s) < 2: return len(s) | |
subs = [] | |
for x in range(0, len(s)): |
This file contains hidden or 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 removeDuplicates(self, nums: List[int]) -> int: | |
if len(nums) < 2: return len(nums) | |
length = 1 | |
cur = 0 | |
future = 1 | |
while future < len(nums): | |
if nums[cur] == nums[future]: | |
nums[future] = 0 |
This file contains hidden or 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 typing import List | |
def int_to_array(x: int) -> List[int]: | |
result = [] | |
while x > 0: | |
tmp = x % 10 | |
result.append(tmp) | |
x = int((x - tmp) / 10) |
This file contains hidden or 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 interval_overlap(i1, i2): | |
if i1.end >= i2.start: | |
return True | |
else: | |
return False | |
def merge_interval(i1, i2): | |
return Interval(s=min(i1.start, i2.start), e=max(i1.end, i2.end)) |
NewerOlder