- 博客(93)
- 资源 (9)
- 收藏
- 关注
原创 169. Majority Element
class Solution(object): def majorityElement(self, nums): """ :type nums: List[int] :rtype: int """ n=len(nums) nums.sort() l,r=0,n-1
2017-05-25 19:37:28 209
原创 162. Find Peak Element
class Solution(object): def findPeakElement(self, nums): """ :type nums: List[int] :rtype: int """ l=0 r=len(nums)-1 while l
2017-05-25 19:29:26 228
原创 122. Best Time to Buy and Sell Stock II
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ res=0 for i in range(1,len(prices)):
2017-05-25 11:52:01 304
原创 121Best Time to Buy and Sell Stock
class Solution(object): def maxProfit(self, prices): """ :type prices: List[int] :rtype: int """ if not prices or len(prices)==0: return
2017-05-25 10:43:40 192
原创 120. Triangle
class Solution(object): def minimumTotal(self, triangle): """ :type triangle: List[List[int]] :rtype: int """ n=len(triangle) dp=[0]*n
2017-05-24 17:05:07 208
原创 119. Pascal's Triangle II
class Solution(object): def getRow(self, rowIndex): """ :type rowIndex: int :rtype: List[int] """ pre=[1,1] if rowIndex==0: retu
2017-05-24 15:22:41 177
原创 118. Pascal's Triangle
class Solution(object): def generate(self, numRows): """ :type numRows: int :rtype: List[List[int]] """ res=[] if numRows==0: re
2017-05-24 15:04:28 221
原创 106Construct Binary Tree from Inorder and Postorder Traversal
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object):
2017-05-24 12:30:57 203
原创 Construct Binary Tree from Preorder and Inorder Traversal
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(objec
2017-05-24 11:13:25 224
原创 二叉树的遍历
1.二叉树遍历方式:先序遍历,后续遍历,中序遍历,层次遍历先 if(BT):getRootleftright中if (BT)leftget rootright后if(BT):leftrightgetroot每个节点遇到三次,先序是第一次取数字,中序点二次取,后续点三次取。路径一样,出口一样,入口一样
2017-05-24 10:14:12 215
原创 79. Word Search
class Solution(object): def exist(self, board, word): """ :type board: List[List[str]] :type word: str :rtype: bool """ for i in range(len(boar
2017-05-22 15:47:58 217
原创 566. Reshape the Matrix
class Solution(object): def matrixReshape(self, nums, r, c): """ :type nums: List[List[int]] :type r: int :type c: int :rtype: List[List[int]]
2017-05-22 14:32:32 265
转载 54. Spiral Matrix
class Solution(object): def spiralOrder(self, matrix): """ :type matrix: List[List[int]] :rtype: List[int] """ ret = [] while matrix:
2017-05-19 17:08:40 254
原创 Combination Sum II
class Solution(object): def combinationSum2(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """
2017-05-19 16:21:39 170
原创 39. Combination Sum
class Solution(object): def combinationSum(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """
2017-05-19 16:01:03 175
原创 34. Search for a Range
class Solution(object): def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ l,r=0,len(nums
2017-05-19 11:34:23 232
原创 35. Search Insert Position
class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ n=len(nums)
2017-05-19 10:10:16 201
原创 [leetcode 561]Array Partition I
题目:求2n个数字的数组组成n对中的每个小数字之和最大nums.sort() return sum(nums[::2])
2017-05-18 15:31:36 229
原创 [leetcode 560]Subarray Sum Equals K
题目:求连续子集和为k的个数代码出自:https://discuss.leetcode.com/topic/88041/super-simple-pythonclass Solution(object): def subarraySum(self, nums, k): """ :type nums: List[int] :type k: int ...
2017-05-18 15:13:18 528
原创 [leetcode525]Contiguous Array
class Solution(object): def findMaxLength(self, nums): """ :type nums: List[int] :rtype: int """ for i in range(len(nums)): if nums[i]==0
2017-05-17 17:45:38 452
转载 [leetcode523]Continuous Subarray Sum
https://leetcode.com/problems/continuous-subarray-sum/#/solutionsclass Solution(object): def checkSubarraySum(self, nums, k): """ :type nums: List[int] :type k:
2017-05-17 17:17:25 283
原创 [leetcode462] Minimum Moves to Equal Array Elements II
class Solution(object): def minMoves2(self, nums): """ :type nums: List[int] :rtype: int """ l,r ,count = 0,len(nums)-1,0 nums.sort()
2017-05-17 16:40:01 289
原创 [return sum(nums)-min(nums)*len(nums)leetcode453】 Minimum Moves to Equal Array Elements
题意: 每次移动可以加1,移动的时候只能移动n-1个,需要移动多少次可以使得数组值都相等python :return sum(nums)-min(nums)*len(nums)class Solution(object): def minMoves(self, nums): """ :type nums: List[int]
2017-05-17 16:10:38 331
原创 [leetcode 448]Find All Numbers Disappeared in an Array
同442一样,只是判断条件不一样class Solution(object): def findDisappearedNumbers(self, nums): """ :type nums: List[int] :rtype: List[int] """ f=[0]*(len(nums)
2017-05-17 15:16:26 303
原创 leetcode442 Find All Duplicates in an Array
解题思路:将值转化为下表,用值记录个数代码来自:https://leetcode.com/problems/find-all-duplicates-in-an-array/#/descriptionhttps://leetcode.com/problems/find-all-duplicates-in-an-array/#/solutionsclass Solution(objec
2017-05-17 15:05:34 226
原创 [leetcode 410]Split Array Largest Sum
题目理解:给一个非负数组,和划分数组的个数m问题:返回划分的m个子数组中和最大的哪个和,因为划分m个子数组的方法有很多种,假设有k种划分m个子数组的方法,所以就有k个子数组最大和的值,求出这k个值中最小的哪个值返回来。解决:二分查找(代码参考https://discuss.leetcode.com/topic/62139/python-solution-dp-and-binar
2017-05-17 11:23:26 451
原创 leetcode 384shuffle a array
class Solution(object): def __init__(self, nums): """ :type nums: List[int] """ self.nums = nums def reset(self): """ Resets the
2017-05-17 09:40:29 208
原创 330. Patching Array
class Solution(object): def minPatches(self, nums, n): """ :type nums: List[int] :type n: int :rtype: int """ size=len(nums) i,add,
2017-05-15 11:55:02 237
原创 [leetcode238]Product of Array Except Self
class Solution(object): def productExceptSelf(self, nums): """ :type nums: List[int] :rtype: List[int] """ res=[0]*len(nums) res[0]=1
2017-05-15 10:40:33 197
原创 lettcode189Rotate Array
class Solution(object): def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: void Do not return anything, modify nums in-place instead.
2017-05-11 15:45:40 201
原创 leetcode167Two Sum II - Input array is sorted
这个算法易于理解但是效果不是很好class Solution(object): def twoSum(self, numbers, target): """ :type numbers: List[int] :type target: int :rtype: List[int] """
2017-05-11 14:23:35 215
原创 leetcode154Find Minimum in Rotated Sorted Array II
class Solution(object): def findMin(self, nums): """ :type nums: List[int] :rtype: int """ l,r=0,len(nums)-1 while l=nums[r]: mi
2017-05-11 12:53:46 216
原创 letcode153Find Minimum in Rotated Sorted Array
class Solution(object): def findMin(self, nums): """ :type nums: List[int] :rtype: int """ l,r=0,len(nums)-1 while l mid=l+(r-l)
2017-05-11 12:41:19 202
原创 python 报错集合
1.调用一个没有python中已命名过的变量时Line 33: Exception: Type : Not implementedException: Type : Not implemented原因:这是因为调用了python一个固有方法但同时没有实现它例如:print max,print help2.调用一个python中不存在的nin时报错: NameEr
2017-05-11 11:12:22 1272
原创 RNN的理解
场景:一个人x站在一个入口处,一个入口处有一道具w,还有一个来自上面的带着道具的朋友w'x'动作:这个人拿起了道具(此处变为wx)和站在门口的朋友进入了门,门里面有个试衣间,他们两个进入了试衣间合二为一个人(此处为y=wx+w'x'),这时给他们起名为yy出了试衣间,然后他又进入一个屋子,在屋子里他自己倒刺了一番,从屋子里出来后变成了b,最后b在下一个门前手里拿着上次出来时带的道具x等待着
2017-05-10 11:04:28 387
原创 [leetcode 53]Maximum Subarray
class Solution(object): def maxSubArray(self, nums): """ :type nums: List[int] :rtype: int """ if not nums: return None d=[0]*le
2017-05-09 21:46:32 195
原创 [leetcode108]Convert Sorted Array to Binary Search Tree
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(objec
2017-05-09 21:14:45 199
原创 [leetcode 33]Search in Rotated Sorted Array
class Solution(object): def search(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ n=len(nums) l,r=
2017-05-09 11:08:26 172
原创 leetcode31Next Permutation
class Solution(object): def nextPermutation(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """
2017-05-09 10:38:16 167
原创 27. Remove Element
题目:数组中的重复元素都删掉,且返回长度要求:不可另外开空间解题思路:用两个指针,一个指开头,一个指结尾,当开头的与所给值相同时把结尾的值赋值过来,尾指针向前class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int]
2017-05-08 21:34:17 213
ELM回归预测matlab版code
2014-12-16
emd回归预测matlab版code
2014-12-16
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人