摘要: class Solution: def romanToInt(self, s: str) -> int: dic = {} dic["I"] = 1 dic["V"] = 5 dic["X"] = 10 dic["L"] = 50 dic["C"] = 100 dic["D"] = 500 dic[ 阅读全文
posted @ 2020-05-09 15:29 星海寻梦233 阅读(98) 评论(0) 推荐(0)
摘要: class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: if len(strs) == 0: return "" last_s = strs[0] same_prefix = "" for i, s in enum 阅读全文
posted @ 2020-05-09 15:28 星海寻梦233 阅读(97) 评论(0) 推荐(0)
摘要: class Solution: def isValid(self, s: str) -> bool: dic = {"(":")",")":"(","[":"]","]":"[","{":"}","}":"{"} if len(s) == 0: return True else: stack = " 阅读全文
posted @ 2020-05-09 15:26 星海寻梦233 阅读(112) 评论(0) 推荐(0)
摘要: class Solution: def removeDuplicates(self, nums: List[int]) -> int: j = 0 for i in range(len(nums)): if i >j and nums[i] > nums[j] : j += 1 nums[j] = 阅读全文
posted @ 2020-05-09 15:25 星海寻梦233 阅读(102) 评论(0) 推荐(0)
摘要: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def mergeTwoLists(se 阅读全文
posted @ 2020-05-09 15:23 星海寻梦233 阅读(134) 评论(0) 推荐(0)
摘要: class Solution: def removeElement(self, nums: List[int], val: int) -> int: j = 0 for i, v in enumerate(nums): if v != val: nums[j] = v j += 1 return j 阅读全文
posted @ 2020-05-09 15:21 星海寻梦233 阅读(105) 评论(0) 推荐(0)
摘要: class Solution: def strStr(self, haystack: str, needle: str) -> int: if len(needle) == 0: return 0 else: for i in range(len(haystack)): if haystack[i: 阅读全文
posted @ 2020-05-09 15:20 星海寻梦233 阅读(80) 评论(0) 推荐(0)
摘要: class Solution: def searchInsert(self, nums: List[int], target: int) -> int: if len(nums) == 0: return 0 else: for i in range(len(nums)): if nums[i] > 阅读全文
posted @ 2020-05-09 15:19 星海寻梦233 阅读(113) 评论(0) 推荐(0)
摘要: class Solution: def countAndSay(self, n: int) -> str: if n == 1 : return "1" if n == 2: return "11" s = "11" for i in range(2,n): tmp_s = "" count = 1 阅读全文
posted @ 2020-05-09 15:17 星海寻梦233 阅读(156) 评论(0) 推荐(0)
摘要: class Solution: def lengthOfLastWord(self, s: str) -> int: if len(s) == 0: return 0 s = s[::-1] length = 0 for i,v in enumerate(s): if v == " ": if le 阅读全文
posted @ 2020-05-09 15:16 星海寻梦233 阅读(94) 评论(0) 推荐(0)
摘要: class Solution: def maxSubArray(self, nums: List[int]) -> int: n = len(nums) res = float('-inf') tmp = 0 for i in range(n): if tmp < 0: tmp = 0 tmp = 阅读全文
posted @ 2020-05-09 15:15 星海寻梦233 阅读(118) 评论(0) 推荐(0)
摘要: class Solution: def plusOne(self, digits: List[int]) -> List[int]: n = len(digits) s = "" for i in range(n): s += str(digits[i]) s = int(s) + 1 s = st 阅读全文
posted @ 2020-05-09 15:14 星海寻梦233 阅读(75) 评论(0) 推荐(0)
摘要: class Solution: def addBinary(self, a: str, b: str) -> str: n = len(a) if len(a) > len(b) else len(b) a = a[::-1] b = b[::-1] tmp = 0 ans = "" for i i 阅读全文
posted @ 2020-05-09 15:12 星海寻梦233 阅读(107) 评论(0) 推荐(0)
摘要: class Solution: def climbStairs(self, n: int) -> int: dp = [1 for i in range(n+1)] for i in range(2, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[n] 阅读全文
posted @ 2020-05-09 15:10 星海寻梦233 阅读(86) 评论(0) 推荐(0)
摘要: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteDuplicates 阅读全文
posted @ 2020-05-09 15:08 星海寻梦233 阅读(86) 评论(0) 推荐(0)
摘要: 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 阅读全文
posted @ 2020-05-09 15:07 星海寻梦233 阅读(115) 评论(0) 推荐(0)
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
posted @ 2020-05-09 15:05 星海寻梦233 阅读(72) 评论(0) 推荐(0)
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self. 阅读全文
posted @ 2020-05-09 15:04 星海寻梦233 阅读(104) 评论(0) 推荐(0)
摘要: class Solution: def generate(self, numRows: int) -> List[List[int]]: if numRows == 0: return None if numRows == 1: return [[1]] ans = [[1]] for j in r 阅读全文
posted @ 2020-05-09 15:03 星海寻梦233 阅读(105) 评论(0) 推荐(0)
摘要: class Solution: def maxProfit(self, prices: List[int]) -> int: length = len(prices) if length == 0: return 0 minBuyPrice = prices[0] maxProfit = 0 for 阅读全文
posted @ 2020-05-09 15:01 星海寻梦233 阅读(104) 评论(0) 推荐(0)
摘要: class Solution: def singleNumber(self, nums: List[int]) -> int: a = 0 for i in range(len(nums)): a = a^nums[i] return a 阅读全文
posted @ 2020-05-09 14:58 星海寻梦233 阅读(87) 评论(0) 推荐(0)
摘要: class MinStack: def __init__(self): """ initialize your data structure here. """ self.stack = [] def push(self, x: int) -> None: if len(self.stack) == 阅读全文
posted @ 2020-05-09 14:56 星海寻梦233 阅读(70) 评论(0) 推荐(0)
摘要: class Solution: def twoSum(self, numbers: List[int], target: int) -> List[int]: lp = 0 rp = len(numbers) - 1 while lp < rp: if numbers[lp] + numbers[r 阅读全文
posted @ 2020-05-09 14:55 星海寻梦233 阅读(76) 评论(0) 推荐(0)
摘要: class Solution: def majorityElement(self, nums: List[int]) -> int: if len(nums) == 1: return nums[0] dic = {} n = len(nums) // 2 for i in range(len(nu 阅读全文
posted @ 2020-05-09 14:54 星海寻梦233 阅读(64) 评论(0) 推荐(0)
摘要: class Solution: def titleToNumber(self, s: str) -> int: ans = 0 for i in range(len(s)): ans = ans * 26 + ord(s[i])-64 return ans 阅读全文
posted @ 2020-05-09 14:52 星海寻梦233 阅读(118) 评论(0) 推荐(0)
摘要: class Solution: def rotate(self, nums: List[int], k: int) -> None: """ Do not return anything, modify nums in-place instead. """ lenList = len(nums) w 阅读全文
posted @ 2020-05-09 14:51 星海寻梦233 阅读(79) 评论(0) 推荐(0)
摘要: class Solution: def trailingZeroes(self, n: int) -> int: if n < 5: return 0 return n//5 + self.trailingZeroes(n//5) 阅读全文
posted @ 2020-05-09 14:49 星海寻梦233 阅读(62) 评论(0) 推荐(0)
摘要: class Solution: def convertToTitle(self, n: int) -> str: ans = "" while n: a = (n-1) % 26 n = (n-1) // 26 ans = chr(ord('A') + a) + ans return ans 阅读全文
posted @ 2020-05-09 14:47 星海寻梦233 阅读(89) 评论(0) 推荐(0)
摘要: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def getIntersectionN 阅读全文
posted @ 2020-05-09 14:45 星海寻梦233 阅读(91) 评论(0) 推荐(0)
摘要: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def hasCycle(self, h 阅读全文
posted @ 2020-05-09 14:43 星海寻梦233 阅读(178) 评论(0) 推荐(0)
摘要: class Solution: def isPalindrome(self, s: str) -> bool: s1 = s.split() s_tmp = "" for i in range(len(s1)): for j in range(len(s1[i])): if 'a'<= s1[i][ 阅读全文
posted @ 2020-05-09 14:41 星海寻梦233 阅读(83) 评论(0) 推荐(0)
摘要: class Solution: def maxProfit(self, prices: List[int]) -> int: length = len(prices) if length == 0: return 0 maxProfit = 0 minBuyPrice = prices[0] for 阅读全文
posted @ 2020-05-09 14:39 星海寻梦233 阅读(111) 评论(0) 推荐(0)
摘要: class Solution: def getRow(self, rowIndex: int) -> List[int]: ans = [1] for i in range(rowIndex + 1): tmp = [1 for i in range(i + 1)] for j in range(1 阅读全文
posted @ 2020-05-09 14:38 星海寻梦233 阅读(68) 评论(0) 推荐(0)
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self. 阅读全文
posted @ 2020-05-09 14:37 星海寻梦233 阅读(105) 评论(0) 推荐(0)
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self. 阅读全文
posted @ 2020-05-09 14:35 星海寻梦233 阅读(93) 评论(0) 推荐(0)
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
posted @ 2020-05-09 14:33 星海寻梦233 阅读(100) 评论(0) 推荐(0)
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
posted @ 2020-05-09 14:32 星海寻梦233 阅读(68) 评论(0) 推荐(0)
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
posted @ 2020-05-09 14:31 星海寻梦233 阅读(92) 评论(0) 推荐(0)
摘要: # Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
posted @ 2020-05-09 14:30 星海寻梦233 阅读(94) 评论(0) 推荐(0)
摘要: class Solution: def isPalindrome(self, x: int) -> bool: if x < 0: return False else: x_copy = x pal_num = 0 while x: pal_num = pal_num *10 + x % 10 x 阅读全文
posted @ 2020-05-09 14:27 星海寻梦233 阅读(92) 评论(0) 推荐(0)
摘要: class Solution: def reverse(self, x: int) -> int: isNegative = x < 0 sum = 0 abs_x = abs(x) while abs_x: sum = sum * 10 i = abs_x % 10 sum = sum + i a 阅读全文
posted @ 2020-05-09 14:11 星海寻梦233 阅读(122) 评论(0) 推荐(0)
摘要: class Solution: def twoSum(self, nums, target): """ :param nums: List[int] :param target:int :return:Lsit[int] """ reverse = {} for i , v in enumerate 阅读全文
posted @ 2020-05-09 14:09 星海寻梦233 阅读(99) 评论(0) 推荐(0)