随笔分类 -  leetcode

上一页 1 ··· 18 19 20 21 22
摘要:题目描述: 第一次提交: class Solution: def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None: """ Do not return anything, modify nums1 in- 阅读全文
posted @ 2019-03-13 19:56 oldby 阅读(116) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交: class Solution: def deleteDuplicates(self, head: ListNode) -> ListNode: if head==None or head.next==None: return head head.next = self.de 阅读全文
posted @ 2019-03-13 19:19 oldby 阅读(116) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交:(超时) class Solution: def climbStairs(self, n: int) -> int: if n == 0 or n == 1 or n == 2: return n return self.climbStairs(n - 1) + self.c 阅读全文
posted @ 2019-03-13 18:19 oldby 阅读(126) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交:(会超时) class Solution: def mySqrt(self, x: int) -> int: if x==0 or x==1: return x for i in range(1,x): if i*i<=x and (i+1)**2>x: return i V 阅读全文
posted @ 2019-03-13 12:03 oldby 阅读(277) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交: class Solution: def addBinary(self, a: str, b: str) -> str: list_a,list_b=[],[] for s in a: list_a.append(int(s)) for s in b: list_b.appe 阅读全文
posted @ 2019-03-12 21:32 oldby 阅读(144) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交: class Solution: def plusOne(self, digits): digits[-1]=digits[-1]+1 for i in range(len(digits)-1,0,-1): if digits[i]==10: digits[i]=0 digi 阅读全文
posted @ 2019-03-12 19:33 oldby 阅读(320) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2019-03-12 15:52 oldby 阅读(978) 评论(0) 推荐(0)
摘要:题目描述: 第一次解答: class Solution: def lengthOfLastWord(self, s: str) -> int: L=s.strip().split(" ") if L[-1]=="" : return 0 return len(L[-1]) 优化后: class So 阅读全文
posted @ 2019-03-12 15:50 oldby 阅读(104) 评论(0) 推荐(0)
摘要:题目描述: 方法一:O(N) class Solution(object): def maxSubArray(self, nums): sum = 0 max_sub_sum = nums[0] for num in nums: sum += num if sum > max_sub_sum: ma 阅读全文
posted @ 2019-03-12 14:08 oldby 阅读(150) 评论(0) 推荐(0)
摘要:恢复内容开始 题目描述: 第一次提交: class Solution: def countAndSay(self, n: int) -> str: f = "1" for i in range(n-1): count = 0 c = '' for j in range(len(f)): if j = 阅读全文
posted @ 2019-03-12 11:27 oldby 阅读(217) 评论(0) 推荐(0)
摘要:题目: 第一次提交; class Solution: def searchInsert(self, nums: List[int], target: int) -> int: for i in range(len(nums)): if nums[i] >= target : return i if 阅读全文
posted @ 2019-03-11 18:15 oldby 阅读(172) 评论(0) 推荐(0)
摘要:题目: 第一次提交: class Solution: def strStr(self, haystack: str, needle: str) -> int: if not len(needle): return 0 for i in range(len(haystack)): if i+len(n 阅读全文
posted @ 2019-03-11 13:37 oldby 阅读(225) 评论(0) 推荐(0)
摘要:题目: 第一次提交: class Solution: def removeElement(self, nums, val: int) -> int: for i in range(len(nums)-1,-1, -1):#此处中间为range(,中间值为-1,) if nums[i] == val: 阅读全文
posted @ 2019-03-11 12:22 oldby 阅读(95) 评论(0) 推荐(0)
摘要:题目描述: 第一次提交: class Solution: def removeDuplicates(self, nums) -> int: for i in range(len(nums)-1,0,-1):#注意要倒序** if nums[i]==nums[i-1]: del(nums[i]) re 阅读全文
posted @ 2019-03-10 20:55 oldby 阅读(113) 评论(0) 推荐(0)
摘要:题目描述: 方法一: # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: def merge 阅读全文
posted @ 2019-03-10 20:30 oldby 阅读(163) 评论(0) 推荐(0)
摘要:python字符串与列表的相互转换 学习内容: 1.字符串转列表 2.列表转字符串 1. 字符串转列表 str1 = "hi hello world" print(str1.split(" "))输出:['hi', 'hello', 'world'] 2. 列表转字符串 l = ["hi","hel 阅读全文
posted @ 2019-03-10 14:17 oldby 阅读(167) 评论(0) 推荐(0)
摘要:笔记: python if not 判断是否为None的情况 if not x if x is None if not x is None if x is not None`是最好的写法,清晰,不会出现错误,以后坚持使用这种写法。 使用if not x这种写法的前提是:必须清楚x等于None, Fa 阅读全文
posted @ 2019-03-10 13:03 oldby 阅读(373) 评论(0) 推荐(0)
摘要:错误记录 class Solution: def romanToInt(self, s: str) -> int: d = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000} r=0 for i in range(len(s)): if d[s[ 阅读全文
posted @ 2019-03-09 18:06 oldby 阅读(157) 评论(0) 推荐(0)
摘要:题目描述 方法一:转换为字符串 class Solution: def isPalindrome(self, x: int) -> bool: if x<0: return False else: y=str(x)[::-1] return y==str(x) 方法二;数字反转 class Solu 阅读全文
posted @ 2019-03-09 17:19 oldby 阅读(142) 评论(0) 推荐(0)
摘要:Python join()方法 join()方法语法: str.join(sequence) 参数 sequence -- 要连接的元素序列。 返回值 返回通过指定字符连接序列中元素后生成的新字符串。 实例 #!/usr/bin/python # -*- coding: UTF-8 -*- str 阅读全文
posted @ 2019-03-09 16:42 oldby 阅读(252) 评论(0) 推荐(0)

上一页 1 ··· 18 19 20 21 22