leetcode
红金龙-时光
这个作者很懒,什么都没留下…
展开
-
leetcode 2:Add Two Numbers
Runtime: 208 ms, faster than 16.64% of Python3 online submissions for Add Two Numbers.原谅我,指针我已经不知道知道哪里去了。。。。# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# ...原创 2018-12-26 14:24:53 · 399 阅读 · 0 评论 -
leetcode 21:Merge Two Sorted Lists
Runtime: 68 ms, faster than 28.06% of Python3 online submissions for Merge Two Sorted Lists.由于对python指针不熟悉,参考了一下其他同学的写法这题就是标准的数据结构题目,学过数据结构的同学应该都见过类似的题目好像是 尾插法# Definition for singly-linked list....原创 2018-12-26 10:05:44 · 145 阅读 · 0 评论 -
leetcode 58: Length of Last Word.
Runtime: 52 ms, faster than 29.03% of Python3 online submissions for Length of Last Word.class Solution: def lengthOfLastWord(self, s): """ :type s: str :rtype: int ...原创 2018-12-26 09:12:51 · 272 阅读 · 0 评论 -
leetcode 43: Multiply Strings
Runtime: 64 ms, faster than 75.88% of Python3 online submissions for Multiply Strings.难不成这用其他语言很难???这个还中级难度。。。应该是有其他独特的方法吧class Solution: def multiply(self, num1, num2): """ :typ...原创 2018-12-26 09:08:53 · 353 阅读 · 0 评论 -
leetcode 50: Pow(x, n)
Runtime: 76 ms, faster than 9.52% of Python3 online submissions for Pow(x, n).很简单class Solution: def myPow(self, x, n): """ :type x: float :type n: int :rtype: fl...原创 2018-12-26 09:04:51 · 305 阅读 · 0 评论 -
leetcode 27:Remove Element.
跟26题一个思路Runtime: 60 ms, faster than 23.48% of Python3 online submissions for Remove Element.class Solution: def removeElement(self, nums, val): """ :type nums: List[int] ...原创 2018-12-26 08:56:59 · 299 阅读 · 0 评论 -
leetcode 26: Remove Duplicates from Sorted Array
Runtime: 68 ms, faster than 71.33% of Python3 online submissions for Remove Duplicates from Sorted Array.数据结构里常见的题使用2个类指针,一个从1-n,一个只记录非重复的数据次数class Solution(object): def removeDuplicates(self,...原创 2018-12-25 17:41:42 · 123 阅读 · 0 评论 -
leetcode 35. Search Insert Position
Runtime: 56 ms, faster than 26.42% of Python3 online submissions for Search Insert Position.如果 target > list最后一个数 那就是插入到最后就是挨个比较class Solution: def searchInsert(self, nums, target): ...原创 2018-12-25 16:55:16 · 129 阅读 · 0 评论 -
leetcode18: 4Sum by python3
超时:排序的结果需要用上 后面再修改class Solution: def fourSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[List[int]] """ len_num...原创 2018-12-25 12:32:34 · 131 阅读 · 0 评论 -
leetcode 13 :roman-to-integer
思路很简单 如果 一个数 小于后一个数 那么取负Runtime: 180 ms, faster than 50.44% of Python3 online submissions for Roman to Integer.class Solution: def romanToInt(self, s): """ :type s: str :...原创 2018-12-25 11:24:13 · 107 阅读 · 0 评论 -
leetcode 9 :Palindrome Number by pthon3
Runtime: 476 ms, faster than 29.19% of Python3 online submissions for Palindrome Number.显然 跟第七题一样首先按照题意负数没有回文数一个数的回文数必然等于自己class Solution: def isPalindrome(self, x): """ :ty...原创 2018-12-25 10:51:34 · 102 阅读 · 0 评论 -
leetcode 7 Reverse Integer
88ms : Your runtime beats 23.38 % of python3 submissionsclass Solution: def reverse(self, x): """ :type x: int :rtype: int """ y = abs(x) sum原创 2018-12-24 17:41:21 · 107 阅读 · 0 评论 -
leetcode 1. Two Sum
python3正常方式:双重循环6384 ms :Your runtime beats 7.14 % of python3 submissionsclass Solution: def twoSum(self, nums, target): """ :type nums: List[int] :type target: int ...原创 2018-12-24 16:52:37 · 109 阅读 · 0 评论 -
leetcode 66:Plus One.
Runtime: 52 ms, faster than 35.86% of Python3 online submissions for Plus One.思路:在list最前面加一个0然后倒着循环:L[i] + 1如果结果 = 10 ,那么 L[i] = 0; L[i-1] +1class Solution: def plusOne(self, digits): ...原创 2018-12-28 11:48:29 · 409 阅读 · 0 评论 -
leetcode 69:Sqrt(x)
Runtime: 80 ms, faster than 44.48% of Python3 online submissions for Sqrt(x).学习了一下,可以用牛顿法等方法求解参考:[LeetCode] Sqrt(x) 求平方根class Solution: def mySqrt(self, x): """ :type x: int ...原创 2018-12-26 17:27:13 · 402 阅读 · 0 评论 -
leetcode 28:Implement strStr().
Runtime: 56 ms, faster than 36.86% of Python3 online submissions for Implement strStr().不知道这样子好不,直接用的分隔符分割数据其实在算法中是有这么一个匹配算法的,叫KMP算法,当然还有很多改进版的算法class Solution: def strStr(self, haystack, needl...原创 2018-12-26 10:56:14 · 154 阅读 · 0 评论