- 博客(82)
- 资源 (3)
- 收藏
- 关注
原创 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, he
2017-09-27 19:54:52 242
原创 LeetCode-81-Search in Rotated Sorted Array II 水题
class Solution(object): def search(self, nums, target): """ :type nums: List[int] :type target: int :rtype: bool """ for i in range(len(nums)):
2017-09-27 19:24:38 194
原创 LeetCode-80-Remove Duplicates from Sorted Array II 水题
class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if nums==[]:return 0 Len=len(nums) for i
2017-09-27 15:50:50 747
原创 LeetCode-79-Word Search 爆搜
class Solution(object): d=[[1,0],[0,1],[-1,0],[0,-1]] used=[] def exist(self, board, word): """ :type board: List[List[str]] :type word: str :rtype: bool
2017-09-27 15:31:10 227
原创 LeetCode-78-Subsets 水题暴力
class Solution(object): ans=[] cur=[] def subsets(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ self.ans=[] self.ans.ap
2017-09-27 14:42:31 225
原创 LeetCode-77-Combinations dfs+剪枝
class Solution(object): ans=[] cur=[] def combine(self, n, k): """ :type n: int :type k: int :rtype: List[List[int]] """ self.ans=[]
2017-09-21 20:49:27 217
原创 LeetCode-76-Minimum Window Substring 尺取法+字典
class Solution(object): def minWindow(self, s, t): """ :type s: str :type t: str :rtype: str """ Map={} Lens=len(s) Lent=len(t)
2017-09-21 20:25:19 183
原创 LeetCode-75-Sort Colors 水题
class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ cnts=[0
2017-09-21 19:09:19 213
原创 LeetCode-74-Search a 2D Matrix 二维二分
class Solution(object): def searchMatrix(self, matrix, target): """ :type matrix: List[List[int]] :type target: int :rtype: bool """ Len=len(matrix)
2017-09-21 18:12:21 221
原创 LeetCode-73-Set Matrix Zeroes 水题
class Solution(object): def setZeroes(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """
2017-09-21 17:21:42 257
原创 LeetCode-72-Edit Distance 记忆化搜索DP
class Solution(object): dp=[] def minDistance(self, word1, word2): """ :type word1: str :type word2: str :rtype: int """ self.dp=[[-1 for i in r
2017-09-21 15:25:26 327
原创 LeetCode-71-Simplify Path 无聊模拟
class Solution(object): def simplifyPath(self, path): """ :type path: str :rtype: str """ ans="/" stackLen=1 path+='/' Len=len(path)
2017-09-21 13:16:44 244
原创 LeetCode-70-Climbing Stairs DP水题Fibonacci
class Solution(object): def climbStairs(self, n): """ :type n: int :rtype: int """ if n<=1:return 1 a=1 b=1 c=0 for i in ran
2017-09-21 10:45:44 209
原创 LeetCode-69-Sqrt(x) Python要用math.sqrt()
class Solution(object): def mySqrt(self, x): """ :type x: int :rtype: int """ return int(math.sqrt(x))
2017-09-20 22:43:15 857
原创 LeetCode-68-Text Justification 细节题
很烦的边界条件,还能输入[""],2这种数据的???然后标准输出是[" "],真搞不懂意义何在class Solution(object): def fullJustify(self, words, maxWidth): """ :type words: List[str] :type maxWidth: int :rt
2017-09-20 22:37:45 212
原创 LeetCode-67-Add Binary Python的二十进制互转
注意2进制表示方法是字符串,转出来的二进制带个0b,必要时要去掉class Solution(object): def addBinary(self, a, b): """ :type a: str :type b: str :rtype: str """ return bin(int(a,
2017-09-20 20:27:40 231
原创 LeetCode-66-Plus One 水题
class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ Len=len(digits) jinwei=1 for i in range
2017-09-20 20:20:14 267
原创 LeetCode-65-Valid Number 脑残暴力
class Solution {public: bool isNumber(string s) { enum InputType { INVALID, SPACE, SIGN, DOT, E, DIGIT, LEN }; int trans[][LEN] = { {-1, 0, 1, 2
2017-09-20 19:55:00 267
原创 LeetCode-64-Minimum Path Sum DP水题
class Solution(object): def minPathSum(self, grid): """ :type grid: List[List[int]] :rtype: int """ Lenx=len(grid) if Lenx==0:return 0 Leny=
2017-09-20 19:28:41 190
原创 LeetCode-63-Unique Paths II DP水题
净喜欢给些非法的输入,各种边界条件,真是无语,注重细节就好,这种题真无聊class Solution(object): def uniquePathsWithObstacles(self, obstacleGrid): """ :type obstacleGrid: List[List[int]] :rtype: int
2017-09-20 19:17:47 195
原创 LeetCode-62-Unique Paths DP水题
class Solution(object): def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: int """ if m*n==0:return 0 if m==1 or n==1:return
2017-09-20 18:59:00 175
原创 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, k
2017-09-20 16:32:42 248
原创 LeetCode-60-Permutation Sequence 暴力递归
class Solution(object): ans="" def getPermutation(self, n, k): """ :type n: int :type k: int :rtype: str """ nums=range(1,n+1) ans=[]
2017-09-20 15:37:23 243
原创 LeetCode-59-Spiral Matrix II 模拟水题
class Solution(object): def generateMatrix(self, n): """ :type n: int :rtype: List[List[int]] """ if n==0:return [] d=[[0,1],[1,0],[0,-1],[-1,0]]
2017-09-19 23:23:47 243
原创 LeetCode-58-Length of Last Word 水题
class Solution(object): def lengthOfLastWord(self, s): """ :type s: str :rtype: int """ Len=len(s) endP=Len-1 flag=-1 while(endP>=0)
2017-09-19 22:55:41 247
原创 LeetCode-57-Insert Interval 水
# Definition for an interval.# class Interval(object):# def __init__(self, s=0, e=0):# self.start = s# self.end = eclass Solution(object): def insert(self, intervals, new
2017-09-19 22:47:08 253
原创 LeetCode-56-Merge Intervals Python自定义sort,贪心
# Definition for an interval.# class Interval(object):# def __init__(self, s=0, e=0):# self.start = s# self.end = eclass Solution(object): def comp(self, a, b):
2017-09-19 21:48:05 334
原创 LeetCode-55-Jump Game 贪心水题
class Solution(object): def canJump(self, nums): """ :type nums: List[int] :rtype: bool """ Len=len(nums) if Len<=1:return True reach=0
2017-09-19 21:21:55 309
原创 LeetCode-54-Spiral Matrix 模拟
class Solution(object): def spiralOrder(self, matrix): """ :type matrix: List[List[int]] :rtype: List[int] """ d=[[0,1],[1,0],[0,-1],[-1,0]] Lenm=le
2017-09-19 21:16:18 300
原创 LeetCode-53-Maximum Subarray 贪心
class Solution(object): def maxSubArray(self, nums): """ :type nums: List[int] :rtype: int """ Len=len(nums) startP=-1 for i in range(Len):
2017-09-19 20:48:24 335
原创 LeetCode-52-N-Queens II 同前一题
class Solution(object): N=0 P=[] ans=0 def totalNQueens(self, n): """ :type n: int :rtype: List[List[str]] """ self.N=n s
2017-09-19 18:56:30 266
原创 LeetCode-51-N-Queens 八皇后问题dfs
class Solution(object): N=0 P=[] ans=[] def solveNQueens(self, n): """ :type n: int :rtype: List[List[str]] """ self.N=n self.ans=[]
2017-09-19 17:55:28 824
原创 LeetCode-50-Pow(x, n) 快速幂
class Solution(object): def myPow(self, x, n): """ :type x: float :type n: int :rtype: float """ ans=1; flag=1 if n<0: n
2017-09-19 16:44:16 472
原创 LeetCode-49-Group Anagrams list_to_string、string list
class Solution(object): def groupAnagrams(self, strs): """ :type strs: List[str] :rtype: List[List[str]] """ Len=len(strs) Map={} count=0
2017-09-19 16:16:40 327
原创 LeetCode-48-Rotate Image 矩阵旋转90
一直搞不明白在Python里怎么快速复制一个矩阵class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place in
2017-09-19 13:44:36 386
原创 LeetCode-47-Permutations II 递归+dict
跟上个题差不多,只不过每次我都用set进行了一次Unique操作,然后TLE了。然后我就加了个dict优化一下,头上数字相同的情况下就不进行递归了,然后就A了class Solution(object): def permuteUnique(self, nums): """ :type nums: List[int] :r
2017-09-16 17:57:13 196
原创 LeetCode-46-Permutations 暴力递归
class Solution(object): def permute(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ Len=len(nums) if Len==0:return [] if
2017-09-16 17:23:43 243
原创 LeetCode-45-Jump Game II DP
这个题是典型的DP了,LeetCode有一点很不好,他不告诉你数据量大小,我就直接写了个很暴力的n方的dp然后挂在一组25000长度的数据上,然后我就在原来的基础上进行了剪枝,加了一个step,记录一下每个step最远能走到哪,就优化成On的了然后就过了。找了一下题解,发现有更简单的,空间复杂度O1的方法。。。"""public int jump(int[] A) { if(A=
2017-09-16 16:26:58 289 1
原创 LeetCode-44-Wildcard Matching DP
dp[i][j]指s的前i个和p的前j个是否匹配,dp[0][0]指s和p为空时,初始化为True,其他全为F把p开头的所有的*都找出来,初始化dp[0][j]为T,因为后面dp的时候就从1开始了,不更新0了然后就是根据p[j]分类讨论就行DP:"""public boolean isMatch_2d_method(String s, String p) { int m
2017-09-15 22:39:44 281
原创 LeetCode-43-Multiply Strings 模拟
真无聊的题目,1行代码搞定,Python大法好class Solution(object): def multiply(self, num1, num2): """ :type num1: str :type num2: str :rtype: str """ return str(int(
2017-09-15 19:38:18 154
编译原理 LR(0)项目集规范族的构造 LR(0)分析表+分析串的代码实现
2015-12-06
编译原理 NFA_DFA 画图 C#
2015-11-28
编译原理NFA-DFA转化原创代码以及算法详解
2015-11-28
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人