- 博客(12)
- 收藏
- 关注
原创 力扣Sqrt(x)
class Solution: def mySqrt(self, x: int) -> int: if x == 1 : return 1 elif x == 0 : return 0 for i in range (2,x+1): if i*i > x : return i-1
2021-11-06 10:41:48
99
1
原创 二进制求和
class Solution: def addBinary(self, a: str, b: str) -> str: return bin(int(a,2)+int(b,2))[2:]
2021-11-04 17:03:15
75
原创 最后一个单词的长度(无脑写法)
class Solution: def lengthOfLastWord(self, s: str) -> int: l = [] n = -1 for i in s.split(" ") : l.append(i) while len(l[n]) == 0 : n -= 1 num = len(l[n]) return num
2021-11-03 13:20:03
71
原创 最大子序和
class Solution: def maxSubArray(self, nums: List[int]) -> int: Max = nums[0] nums2 = [] nums2.append(nums[0]) for i in range(1,len(nums)) : nums2.append(max(nums[i],nums[i]+nums2[i-1])) Max ...
2021-11-02 15:01:17
82
原创 分糖果(凑字数)
class Solution: def distributeCandies(self, candyType: List[int]) -> int: n = len(candyType)/2 candyType1 = set(candyType) if len(candyType1) >= n : return int(n) else : return ...
2021-11-01 23:28:21
184
原创 二分思想(搜索插入位置)
class Solution: def searchInsert(self, nums: List[int], target: int) -> int: small = 0 big = len(nums)-1 while small <= big : mid = (big + small) // 2 if nums[mid] == target : r...
2021-11-01 11:40:11
86
原创 实现strStr(借鉴别人的思路)
class Solution: def strStr(self, haystack: str, needle: str) -> int: if len(needle) == 0 :return 0 if needle not in haystack :return -1 for i in range (len(haystack)) : if haystack[i:i+len(needle)] == needle :...
2021-10-29 17:42:27
41
原创 2021-10-28删除有序数组中的重复项
class Solution: def removeDuplicates(self, nums: List[int]) -> int: slow,fast = 0,1 while fast < len(nums) : if nums[slow] != nums[fast] : slow += 1 nums[slow] = nums[fast] ...
2021-10-28 13:35:46
39
原创 2021-10-27最长公共前缀(借鉴别人的)
class Solution: def longestCommonPrefix(self, strs: List[str]) -> str: result = '' n = 0 for i in zip(*strs) : print(i) if len(set(i)) == 1: result += i[n] n += n .
2021-10-27 11:35:18
47
原创 二维数组中的查找
class Solution: def Find(self , target: int, array: List[List[int]]) -> bool: result = False if array == None or array[0] == None : return result for i in array: for j in i: if target..
2021-10-26 16:12:03
51
原创 day3整数反转
class Solution: def reverse(self, x: int) -> int: y = 0 if x < 0: x = -x while x: y = y * 10 y -= x % 10 x = x//10 elif x > 0: while x.
2021-10-25 13:56:15
51
原创 2021-10-24俩数之和(简单)
class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: s = len(nums) for i in range (s): for j in range (len(nums[:i])): if target == nums[i] + nums[j] : return [.
2021-10-24 12:15:36
42
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人