摘要:
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[ 阅读全文
摘要:
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 阅读全文
摘要:
class Solution: def isValid(self, s: str) -> bool: dic = {"(":")",")":"(","[":"]","]":"[","{":"}","}":"{"} if len(s) == 0: return True else: stack = " 阅读全文
摘要:
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] = 阅读全文
摘要:
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def mergeTwoLists(se 阅读全文
摘要:
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 阅读全文
摘要:
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: 阅读全文
摘要:
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] > 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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 = 阅读全文
摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
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] 阅读全文
摘要:
# Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def deleteDuplicates 阅读全文
摘要:
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 阅读全文
摘要:
# Definition for a binary tree node. # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution: 阅读全文
摘要:
# Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=None, right=None): # self.val = val # self.left = left # self. 阅读全文
摘要:
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 阅读全文
摘要:
class Solution: def maxProfit(self, prices: List[int]) -> int: length = len(prices) if length == 0: return 0 minBuyPrice = prices[0] maxProfit = 0 for 阅读全文