随笔分类 -  leetcode

上一页 1 ··· 3 4 5 6 7 8 下一页
leetcode刷题记录
摘要:看着挺简单,结果不断出错不断修改,就很容易绕晕了,用了一个小时四十分钟左右才完成。。。好慢哦: class Solution(object): def myAtoi(self, str): """ :type str: str :rtype: int """ a=str.lstrip() if le 阅读全文
posted @ 2019-10-11 17:23 欣姐姐 阅读(274) 评论(0) 推荐(0)
摘要:class Solution(object): def convert(self, s, numRows): """ :type s: str :type numRows: int :rtype: str """ if numRows==1: return s if len(s)<2: return 阅读全文
posted @ 2019-10-11 15:58 欣姐姐 阅读(151) 评论(0) 推荐(0)
摘要:class Solution: def isPalindrome(self, s: str) -> bool: import re from string import punctuation add_punc="' '" all_punc=add_punc+punctuation b=''.joi 阅读全文
posted @ 2019-10-09 16:26 欣姐姐 阅读(156) 评论(0) 推荐(0)
摘要:class Solution: def searchRange(self, nums: List[int], target: int) -> List[int]: a=nums.count(target) if a==0: return [-1,-1] else: d=nums.index(targ 阅读全文
posted @ 2019-10-08 17:29 欣姐姐 阅读(212) 评论(0) 推荐(0)
摘要:——2019.10.8 我太蠢了,当时并不知道什么是logn级别,就暴力瞎写,啥也不懂,十分尴尬。 二分法,确定边界 public int search(int[] nums, int target) { //未知位置发生旋转,如何确定是哪个位置发生的? //二分法如何使用,如何判断边界? int 阅读全文
posted @ 2019-10-08 17:05 欣姐姐 阅读(144) 评论(0) 推荐(0)
摘要:自己做出来效果并不是很好: class Solution: def removeDuplicates(self, nums) -> int: i=0 while i<len(nums)-2: j,k=i+1,i+2 if nums[i]==nums[j]: if nums[j]==nums[k]: 阅读全文
posted @ 2019-10-08 16:50 欣姐姐 阅读(173) 评论(0) 推荐(0)
摘要:双指针: class Solution: def removeDuplicates(self, nums) -> int: if len(nums)<2: return len(nums) i,j=0,1 while j<len(nums): if nums[i]==nums[j]: nums.po 阅读全文
posted @ 2019-10-08 16:30 欣姐姐 阅读(172) 评论(0) 推荐(0)
摘要:我自己做了一上午还是有错误,参考了别人的,一目了然。 双指针!!! class Solution: def fourSum(self, nums, target: int): n = len(nums) if n < 4: return [] nums.sort() res = [] for i i 阅读全文
posted @ 2019-10-08 16:09 欣姐姐 阅读(166) 评论(0) 推荐(0)
摘要:class Solution: def trap(self, height) -> int: if len(height)<2: return 0 H=max(height) I=height.index(H) S=H*len(height) #print(S) S_1=sum(height) #p 阅读全文
posted @ 2019-10-08 10:17 欣姐姐 阅读(206) 评论(0) 推荐(0)
摘要:双指针法: class Solution: def maxArea(self, height) -> int: if len(height)<=1: return 0 #双指针法 i,j,S=0,len(height)-1,0 while i<j: if height[i]<height[j]: S 阅读全文
posted @ 2019-10-07 22:19 欣姐姐 阅读(221) 评论(0) 推荐(0)
摘要:我自己写的超时了。。。。 class Solution: def threeSum(self, nums) : nums.sort() #print(nums) nums1=[] s=[] if nums.count(0)>=3: s.append([0,0,0]) for i in range(l 阅读全文
posted @ 2019-10-07 19:51 欣姐姐 阅读(156) 评论(0) 推荐(0)
摘要:class Solution: def findMedianSortedArrays(self, nums1, nums2) -> float: c=sorted(nums1+nums2) if len(c)%2==0: return (c[len(c)//2]+c[len(c)//2-1])/2 阅读全文
posted @ 2019-10-07 13:45 欣姐姐 阅读(162) 评论(0) 推荐(0)
摘要:class Solution: def singleNumber(self, nums) -> int: k={} i=0 while i < len(nums): m=nums[i] if m in k.keys(): k[m]=2 i+=1 else: k[m]=1 i+=1 for i,j i 阅读全文
posted @ 2019-09-30 16:51 欣姐姐 阅读(158) 评论(0) 推荐(0)
摘要:class Solution: def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ #print(len(matrix))#行数 #p 阅读全文
posted @ 2019-09-29 14:33 欣姐姐 阅读(146) 评论(0) 推荐(0)
摘要:1 class Solution: 2 def climbStairs(self, n: int) -> int: 3 #假设爬了x次一个台阶,y个两次台阶 4 #求x与y的组合序列 5 if n==0: 6 return 0 7 m=0 8 for x in range(n+1): 9 #prin 阅读全文
posted @ 2019-09-27 10:22 欣姐姐 阅读(193) 评论(0) 推荐(0)
摘要:超出时间限制。。 1 class Solution: 2 def mySqrt(self, x: int) -> int: 3 for i in range(0,x//2+2): 4 if x>=i**2 and x<(i+1)**2: 5 return i 好气哦。。。加油想想怎么改进。。。 修改 阅读全文
posted @ 2019-09-25 11:56 欣姐姐 阅读(200) 评论(0) 推荐(0)
摘要:class Solution: def isSameTree(self, p, q) -> bool: if not p and not q: return True elif p is not None and q is not None: if p.val==q.val: return self 阅读全文
posted @ 2019-09-24 17:00 欣姐姐 阅读(134) 评论(0) 推荐(0)
摘要:1 class Solution: 2 def searchInsert(self, nums, target: int) -> int: 3 if target in nums: 4 return nums.index(target) 5 else: 6 if target>=nums[-1]: 阅读全文
posted @ 2019-09-24 10:48 欣姐姐 阅读(190) 评论(0) 推荐(0)
摘要:早上两个小时才写出来,但是运行超时。。。 感觉自己是真的不会算法,应该系统学习一下才对。 代码我先粘在这里,然后慢慢优化: 要加油哦,学算法!!!!! ——2019.9.20 之前的惨不忍睹,已删。 方法一,暴力法,重点就是判断一个字符串是否是回文子串,以及设置两个参数来返回最后结果, 即,只需要记 阅读全文
posted @ 2019-09-20 11:51 欣姐姐 阅读(254) 评论(1) 推荐(0)
摘要:用时8分20秒: public int maxProfit(int[] prices) { int n = prices.length; if(n<=1) return 0; int min_price = prices[0]; int interest = 0; for(int i = 1;i<n 阅读全文
posted @ 2019-09-19 15:49 欣姐姐 阅读(130) 评论(0) 推荐(0)

上一页 1 ··· 3 4 5 6 7 8 下一页