摘要: 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 阅读(91) 评论(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 阅读(88) 评论(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 阅读(103) 评论(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 阅读(97) 评论(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 阅读(120) 评论(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 阅读(96) 评论(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 阅读(69) 评论(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 阅读(106) 评论(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 阅读(146) 评论(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 阅读(84) 评论(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 阅读(112) 评论(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 阅读(71) 评论(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 阅读(103) 评论(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 阅读(81) 评论(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 阅读(75) 评论(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 阅读(106) 评论(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 阅读(64) 评论(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 阅读(95) 评论(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 阅读(98) 评论(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 阅读(96) 评论(0) 推荐(0) 编辑