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(object): | |
def maxProfit(self, prices): | |
""" | |
:type prices: List[int] | |
:rtype: int | |
""" | |
if not prices: | |
return 0 | |
s = 0 | |
for i in range(1, len(prices)): |
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
import re | |
class Solution(object): | |
def isPalindrome(self, s): | |
""" | |
:type s: str | |
:rtype: bool | |
""" | |
t = '' | |
s = s.lower() | |
for c in 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
# Definition for singly-linked list. | |
# class ListNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.next = None | |
class Solution: | |
def swapPairs(self, head: 'ListNode') -> 'ListNode': | |
if not head or not head.next: | |
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 merge(self, nums1: 'List[int]', m: 'int', nums2: 'List[int]', n: 'int') -> 'None': | |
""" | |
Do not return anything, modify nums1 in-place instead. | |
""" | |
r = len(nums1) - 1 | |
i = m - 1 | |
j = len(nums2) - 1 | |
while i >= 0 and j >= 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
# Definition for singly-linked list. | |
# class ListNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.next = None | |
class Solution: | |
def deleteDuplicates(self, head: 'ListNode') -> 'ListNode': | |
cur = head | |
while cur and cur.next: |
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 groupAnagrams(self, strs: 'List[str]') -> 'List[List[str]]': | |
from collections import Counter | |
d = {} | |
for s in strs: | |
c = ''.join(sorted(s)) | |
if c in d: | |
d[c].append(s) | |
else: | |
d[c] = [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
# Definition for a binary tree node. | |
# class TreeNode(object): | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
# 2 3 6 8 10 12 14 20 22 28 30 | |
class Solution(object): | |
def to_bst(self, nums): |
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 a binary tree node. | |
# class TreeNode: | |
# def __init__(self, x): | |
# self.val = x | |
# self.left = None | |
# self.right = None | |
class Solution: | |
def levelOrderBottom(self, root: 'TreeNode') -> 'List[List[int]]': | |
if not root: |
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
# Leetcode https://leetcode.com/problems/top-k-frequent-elements/ | |
def topKFrequent(self, nums, k): | |
""" | |
:type nums: List[int] | |
:type k: int | |
:rtype: List[int] | |
""" | |
from collections import Counter | |
d = Counter() |
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
package code; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.List; | |
class Meeting { | |
public int start; |
NewerOlder