摘要:
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 阅读全文