自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

世靖的码场

AC for AK

  • 博客(237)
  • 资源 (3)
  • 收藏
  • 关注

原创 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 237

原创 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 237

原创 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 245

原创 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 327

原创 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 297

原创 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 289

原创 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 322

原创 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 260

原创 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 795

原创 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 449

原创 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 318

原创 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 372

原创 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 181

原创 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 229

原创 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 279 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 273

原创 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 143

原创 LeetCode-42-Trapping Rain Water 贪心或单调栈

这个题一开始想麻烦了,我用单调栈实现了一下,A了,但是只打败了0.4%的人,后来看了一眼别人的博客,发现没那么麻烦,找到最高点,从左右贪心就行了。。。下面是两份不同做法的代码,时间复杂度都是O(n)class Solution(object): def trap(self, height): """ :type height: List[in

2017-09-15 17:48:27 819

原创 LeetCode-41-First Missing Positive 递归水题

class Solution(object): def firstMissingPositive(self, nums): """ :type nums: List[int] :rtype: int """ Len=len(nums) for i in range(Len):

2017-09-14 17:51:00 190

原创 LeetCode-40-Combination Sum II ,同39

跟上一道题比就改了一个地方,dfs的for循环从下一个开始,上一道是从自己开始dfsclass Solution(object): ansSet=set() def combinationSum2(self, candidates, target): """ :type candidates: List[int] :type ta

2017-09-14 17:05:42 186

原创 LeetCode-39-Combination Sum, 回溯dfs,Python的list.append()覆盖前面,tuple,set

写dfs的时候遇到了一些问题,直接把curAns给加到list里会出问题,需要先赋值一下再添加,赋值可以:newAns=curAns[:]然后再添加就不会出现重复的现象,如果不这么做,添加的实际上是引用,共享curAns的内存,然后curAns变了,list里所有的相关元素都会变,新开一个空间就没事了。这里set里只能存tuple,只有如此才能hash。class

2017-09-14 17:02:41 397

原创 LeetCode-38-Count and Say Python的int_to_string

题意真的很难理解。。。class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str """ if n==1:return "1" s="1" for i in range(n-1)

2017-09-14 14:05:45 227

原创 LeetCode-37-Sudoku Solver, list转字符串join,回溯

class Solution(object): count=0 ans=[[0 for x in range(9)]for y in range(9)] def solveSudoku(self, board): """ :type board: List[List[str]] :rtype: void Do not retu

2017-09-14 01:35:32 228 1

原创 LeetCode-36-Valid Sudoku 位运算状压,python的ascll,char互转

class Solution(object): def isValidSudoku(self, board): """ :type board: List[List[str]] :rtype: bool """ verti=[0]*9 horiz=[0]*9 area=[0]*9

2017-09-12 22:35:01 499

原创 LeetCode-35-Search Insert Position 裸lower_bound

class Solution(object): def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ Len=len(nums) if L

2017-09-12 21:56:07 201

原创 LeetCode-34-Search for a Range Python实现lower_bound

手写 lower_boundclass Solution(object): def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ Len=l

2017-09-12 21:29:03 453

原创 LeetCode-33-Search in Rotated Sorted Array 水题

问世间还能有多水的题class Solution(object): def search(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ for i in range(len(n

2017-09-12 20:20:14 174

原创 LeetCode-32-Longest Valid Parentheses 栈

维护一个栈,栈内元素是pair,代表括号的左右以及所在的位置,先push进去一个,方便计算class Solution(object): def longestValidParentheses(self, s): """ :type s: str :rtype: int """ Len=len(s)

2017-09-12 16:13:32 155

原创 LeetCode-31-Next Permutation 贪心,排序

a.sort()t=sorted(a)class Solution(object): def nextPermutation(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead.

2017-09-11 23:48:08 179

原创 LeetCode-30-Substring with Concatenation of All Words 暴力+Map灵活数据结构

class Solution(object): def findSubstring(self, s, words): """ :type s: str :type words: List[str] :rtype: List[int] """ if s=="" or words==[]:retur

2017-09-11 21:02:39 217

原创 LeetCode-29-Divide Two Integers 智障题

感觉LeetCode的题目跟弱智一样,还题目要求我不能用乘除取模。。。用了也AC了啊。。。还设置一堆边界条件,不能超过int范围,真是ZZclass Solution(object): def divide(self, dividend, divisor): """ :type dividend: int :type divisor: i

2017-09-11 20:15:51 180

原创 LeetCode-28-Implement strStr() KMP模板题

这个题暴力也能过,我用了KMP结果才打败28%,drunkclass Solution(object): def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """

2017-09-11 17:57:47 220

原创 LeetCode-27-Remove Element

class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ Len=len(nums) for i in

2017-09-11 15:39:48 143

原创 LeetCode-26-Remove Duplicates from Sorted Array

class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if nums==[]:return 0 nums.sort() ans=1

2017-09-11 15:02:09 212

原创 LeetCode-25-Reverse-Nodes-in-k-Group 链表递归水题

链表,递归,无聊的题目# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def reverseKGrou

2017-09-11 14:46:54 163

原创 LeetCode-24-Swap-Nodes-in-Pairs 链表递归水题

# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def swapPairs(self, head):

2017-09-11 14:06:47 194

原创 LeetCode-23-Merge-k-Sorted-Lists Python倒循环

这个题本来应该用类似归并排序的思想的,然而我直接暴力了一发就过了。。。不明觉厉# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(o

2017-09-11 13:50:53 745 2

原创 LeetCode-22-Generate-Parentheses 记忆化搜索,Python类变量,set强转list

用递归的记忆化搜索枚举出n组括号的情况class Solution(object): dp=[] def generateParenthesis(self, n): """ :type n: int :rtype: List[str] """ while(n>=len(self.dp)):s

2017-09-10 21:59:05 431

原创 LeetCode-21-Merge-Two-Sorted-Lists 递归水题

# Definition for singly-linked list.# class ListNode(object):# def __init__(self, x):# self.val = x# self.next = Noneclass Solution(object): def mergeTwoLists(self, l1, l

2017-09-10 17:38:15 340

原创 LeetCode-20-Valid-Parentheses 栈 水题 Python 列表删除操作

判断括号合法性,用个栈就行了Python里List 的pop,remove,del用法:a.pop()直接pop最后一个,x=a.pop(3)是pop下标为3的数,同时返回这个数xa.remove(3)是去掉第一个值为3的nodedel a[3]就是删除下标为3的数,这里也可以删除一个区间a[1,3]class Solution(object): def isV

2017-09-10 17:26:43 209

编译原理 LR(0)项目集规范族的构造 LR(0)分析表+分析串的代码实现

编译原理作业:输出LR(0)分析表,并且可以判断一个语句是否符合文法。整个过程我是使用codeblocks的c++编写的,其中用了一下STL标准库中的队列、映射。这是实现功能的详细代码,有注释的伪代码以及测试用的相关样例数据。

2015-12-06

编译原理 NFA_DFA 画图 C#

编译原理老师布置的作业要求程序实现NFA_DFA,然后还要输出图像,这个程序是读取一个txt文档数据然后输出一个DFA图,生产txt文档的程序是用c++写的,在我上传的另一个资源里,这两个一起用会有奇效喔

2015-11-28

编译原理NFA-DFA转化原创代码以及算法详解

编译原理老师讲完NFA_DFA布置的作业,因为我是搞ACM的,这个题目用到的算法自己经常用,于是我就用bfs+dfs+状态压缩乱搞搞弄出个代码来,功能ok,100%原创,仅仅提供大家参考。这个是输出的表格部分,我们的程序还支持自动输出dfa的图形,我感觉画图比这个算法还难。。。在另一个资源里再下载。

2015-11-28

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除