- 博客(246)
- 资源 (3)
- 收藏
- 关注
原创 python写算法题:leetcode: 92. Reverse Linked List II
class Solution(object): def reverseBetween(self, head, m, n): """ :type head: ListNode :type m: int :type n: int :rtype: ListNode """ node=...
2019-07-30 22:41:01
202
原创 python写算法题:leetcode: 91. Decode Ways
class Solution(object): def numDecodings(self, s): """ :type s: str :rtype: int """ cnt1=0 cnt2=0 cnt=0 for i in xrange(len(s)): ...
2019-07-29 04:03:11
138
原创 python写算法题:leetcode: 90. Subsets II
class Solution(object): def subsets(self, nums, ind, unret): if ind<0: unret.add(()) return self.subsets(nums, ind-1, unret) for ret in list(u...
2019-07-26 20:07:41
145
原创 python写算法题:leetcode: 89. Gray Code
class Solution(object): def grayCode(self, n): """ :type n: int :rtype: List[int] """ if n==0: return [0] ret=[0,1] for i in xr...
2019-07-25 17:57:28
176
原创 python写算法题:leetcode: 88. Merge Sorted Array
class Solution(object): def merge(self, nums1, m, nums2, n): """ :type nums1: List[int] :type m: int :type nums2: List[int] :type n: int :rtype: No...
2019-07-24 23:20:48
114
原创 python写算法题:leetcode: 87. Scramble String
class Solution(object): def isScramble(self, s1, s2): if sorted(s1) != sorted(s2): return False if len(s1)<4: return True """ :type s1: str :type s2: st...
2019-07-24 23:02:15
219
原创 python写算法题:leetcode: 86. Partition List
class Solution(object): def partition(self, head, x): """ :type head: ListNode :type x: int :rtype: ListNode """ newhead=None leftNode=None...
2019-07-05 18:34:07
254
原创 python写算法题:leetcode: 85. Maximal Rectangle
class Solution(object): def _largestArea(self, sortHeight, ind, heights, left, right): if right<=left: return 0 if right-left<=1: return heights[lef...
2019-07-05 18:24:48
148
原创 python写算法题:leetcode: 84. Largest Rectangle in Histogram
class Solution(object): def _largestArea(self, sortHeight, ind, heights, left, right): if right<=left: return 0 if right-left<=1: return heights[left...
2019-07-05 18:23:00
238
原创 python写算法题:leetcode: 83. Remove Duplicates from Sorted List
class Solution(object): def deleteDuplicates(self, head): """ :type head: ListNode :rtype: ListNode """ newnodehead = None newnode = None ...
2019-06-29 23:21:39
167
原创 python写算法题:leetcode: 82. Remove Duplicates from Sorted List II
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def deleteDuplicates(self, h...
2019-06-29 23:19:52
228
原创 python写算法题:leetcode: 81. Search in Rotated Sorted Array II
class Solution(object): def _search(self, nums, target, left, right): if left>right: return False if left==right: return nums[left]==target; c...
2019-06-29 23:17:44
205
原创 python写算法题:leetcode: 80. Remove Duplicates from Sorted Array II
class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ pos = 0 repeat=0 lastCh="" for ...
2019-06-29 15:42:38
231
原创 python写算法题:leetcode: 79. Word Search
class Solution(object): def checkDirection(self, w, h, board, ch, directions, direction, searchpath, pathmark): i,j,_=searchpath[-1] pathmark.add((i,j)) for ind,dd in en...
2019-06-29 15:39:00
301
原创 python写算法题:leetcode: 78. Subsets
class Solution(object): def _comb(self, lst, k): if k==0: return [[]] if k==1: return [ [v] for v in lst ] ret=[] n=len(lst) for i in xrange(0...
2019-06-16 04:10:20
185
原创 python写算法题:leetcode: 77. Combinations
class Solution(object): def _comb(self, lst, k): if k==0: return [] if k==1: return [ [v] for v in lst ] ret=[] n=len(lst) for i in xrange(0, ...
2019-06-16 04:05:10
248
原创 python写算法题:leetcode: 76. Minimum Window Substring
class Solution(object): def minWindow(self, s, t): """ :type s: str :type t: str :rtype: str """ ts=set(t) tcnt={} for tt in t: ...
2019-06-13 23:18:05
385
原创 python写算法题:leetcode: 75. Sort Colors
class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: None Do not return anything, modify nums in-place instead. """ left=0...
2019-06-10 18:02:36
211
原创 python写算法题:leetcode: 74. Search a 2D Matrix
class Solution(object): def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ if len(matrix)...
2019-06-10 15:32:09
168
原创 python写算法题:leetcode: 73. Set Matrix Zeroes
class Solution(object): def setZeroes(self, matrix): """ :type matrix: List[List[int]] :rtype: None Do not return anything, modify matrix in-place instead. """ ...
2019-06-10 15:07:59
176
原创 python写算法题:leetcode: 72. Edit Distance
class Solution(object): def minDistance(self, word1, word2): """ :type word1: str :type word2: str :rtype: int """ if len(word1)==0: re...
2019-06-10 10:02:30
222
原创 python写算法题:leetcode: 71. Simplify Path
class Solution(object): def simplifyPath(self, path): """ :type path: str :rtype: str """ paths=path.split('/') outpath=[] for p in paths:...
2019-05-30 17:55:00
167
原创 python写算法题:leetcode: 70. Climbing Stairs
class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int """ n0=0 n1=1 res=n0 for i in xrange(0, n): ...
2019-05-30 13:04:21
242
原创 python写算法题:leetcode: 69. Sqrt(x)
class Solution(object): def mySqrt(self, x): """ :type x: int :rtype: int """ if x==0: return 0 n=1 step=x while step&g...
2019-05-30 12:55:19
266
原创 python写算法题:leetcode: 68. Text Justification
class Solution(object): def fullJustify(self, words, maxWidth): """ :type words: List[str] :type maxWidth: int :rtype: List[str] """ res=[] ...
2019-05-29 13:08:02
252
原创 python写算法题:leetcode: 67. Add Binary
class Solution(object): def addBinary(self, a, b): """ :type a: str :type b: str :rtype: str """ alen=len(a) blen=len(b) totallen=m...
2019-05-28 15:56:37
169
原创 python写算法题:leetcode: 66. Plus One
class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ digits.reverse() digits[0]+=1 nextv=0...
2019-05-28 15:17:23
183
原创 python写算法题:leetcode: 65. Valid Number
class Solution(object): def isDigital(self,s): if len(s)==0: return False if s[0]=='-' or s[0]=='+': s=s[1:] return self.pureNum(s) def i...
2019-05-28 15:02:53
202
原创 python写算法题:leetcode: 64. Minimum Path Sum
class Solution(object): def __init__(self): self.sum={} def minPathSum(self, grid): """ :type grid: List[List[int]] :rtype: int """ w=len(grid...
2019-05-27 15:12:38
228
原创 python写算法题:leetcode: 63. Unique Paths II
class Solution(object): def __init__(self): self.cnt={} self.cnt[(0,0)]=1 def uniquePathsWithObstacles(self, obstacleGrid): """ :type obstacleGrid: List[Lis...
2019-05-27 14:54:18
158
原创 python写算法题:leetcode: 62. Unique Paths
class Solution(object): def __init__(self): self.cnt={} self.cnt[(0,0)]=1 def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: ...
2019-05-27 14:52:39
233
原创 python写算法题:leetcode: 61. Rotate List
# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def rotateRight(self, head, ...
2019-05-27 09:57:29
172
原创 python写算法题:leetcode: 60. Permutation Sequence
class Solution(object): def permutation(self, narray, k, p): if len(narray)<=1: return narray ind=k/p rem=k%p p/=len(narray)-1 ret=[narray[...
2019-05-27 09:55:32
230
原创 python写算法题:leetcode: 59. Spiral Matrix II
class Solution(object): def val(self, n, x, y): px=n-1-abs(2*x-n+1) py=n-1-abs(2*y-n+1) v=min(px,py) if v>=n-1: return n*n v/=2 pas...
2019-05-27 00:35:23
215
原创 python写算法题:leetcode: 58. Length of Last Word
class Solution(object): def lengthOfLastWord(self, s): """ :type s: str :rtype: int """ ret=0 lastch = len(s)-1 for _ in xrange(len(s)): ...
2019-05-26 23:23:32
214
原创 python写算法题:leetcode: 57. Insert Interval
class Solution(object): def insert(self, intervals, newInterval): """ :type intervals: List[List[int]] :type newInterval: List[int] :rtype: List[List[int]] ...
2019-05-26 23:14:05
237
原创 python写算法题:leetcode: 56. Merge Intervals
class Solution(object): def merge(self, intervals): """ :type intervals: List[List[int]] :rtype: List[List[int]] """ if len(intervals)==0: retu...
2019-05-19 22:43:28
193
原创 python写算法题:leetcode: 55. Jump Game
class Solution(object): def jump(self, nums, start, end): nstop=0 for i in xrange(start, end): if nstop<i+nums[i]: nstop=i+nums[i] ...
2019-05-17 12:48:31
221
原创 python写算法题:leetcode: 54. Spiral Matrix
class Solution(object): def drawCircle(self, matrix, lefttop, size): print lefttop, size ret=[] for i in xrange(size[0]): ret.append(matrix[lefttop[1]][lefttop...
2019-05-15 17:18:34
201
原创 python写算法题:leetcode: 53. Maximum Subarray
class Solution(object): def maxSubArray(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums)<=0: return 0 tmp=0 maxv=num...
2019-05-09 23:29:24
194
gameboy advanced for motorola
2008-04-10
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人