- 浏览: 201257 次
- 性别:
- 来自: 杭州
最新评论
-
hthhit:
...
回溯算法之N皇后问题(java实现) -
huntfor:
249326109 写道这个算法的复杂度有考虑过么O(n^2) ...
[leetcode]Longest Valid Parentheses -
249326109:
这个算法的复杂度有考虑过么
[leetcode]Longest Valid Parentheses -
huntfor:
249326109 写道又搜到你的了 你怎么搜的,为啥我搜不到 ...
[leetcode]Sort Colors -
249326109:
又搜到你的了
[leetcode]Sort Colors
文章列表
新博文地址:[leetcode]Subsets
Subsets
Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,3], a solution is: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1 ...
新博文地址:[leetcode]Combinations
Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For example, If n = 4 and k = 2, a solution is: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ]
组合,今天排列组合求的略多啊。
DFS实现 ...
新博文总结了三种算法,新博文地址:[leetcode]Merge k Sorted Lists
Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.
K路归并,不知道大家对2路归并还有木有印象,如果木有的话,请戳这里。
其实K路归并,就是进行k - 1 次二路归并,完全一样。
代码如下:
public ListNode mergeKLists(ArrayList<ListNode& ...
新博文地址:[leetcode]Generate Parentheses
感觉新写的代码可读性稍稍好点(≧▽≦)/~~(≧▽≦)/~
Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", ...
新博文地址:[leetcode]Valid Parentheses
Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all valid but "(]" and " ...
新博文地址:[leetcode]Permutations
Permutations
Given a collection of numbers, return all possible permutations. For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].
给你一个数组,求该数组的排列。
如果不了解排列的话,最好先去熟悉一下排列组合的相关概念,对于n个数来说,其排列数组一共有n!种情况,简单起见,我们假设 ...
新博文地址:[leetcode]Valid Number
Valide Number
Validate if a given string is numeric. Some examples: "0" => true " 0.1 " => true "abc" => false "1 a" => false "2e10" => true Note: It is intended for the problem statement to be ambiguou ...
Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any point in time.
很简单的DP问题,只要看下DP的经典例题,转配线调度问题之后,这道题就很简单了。
题中说道只能向下或者向右走,因此到终点[m] ...
新博文地址:[leetcode]Path Sum II
Path Sum II
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \ 4 8 / ...
新博文地址:[leetcode]Path Sum
Path Sum
写道
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \ 4 8 / / ...
KMP算法(1)——java实现
- 博客分类:
- 算法
这篇博文写的实在是太糟蹋了,请大家移步KMP算法小结,如果未能帮大家解惑,请见谅,并欢迎再新博文下面留言讨论。
KMP是比较知名的一个字符串匹配算法。由D.E.Knuth与V.R.Pratt和J.H.Morris同时发现(不明白什么叫同时发现+_+)因此得名KMP算法。
首先大家想一下字符串如何匹配?
比如str1 = “BBC ABCDAB ABCDABCDABDE”,想知道这个字符串中是否包含str2 = “ABCDABD”。
逗逼:“这尼玛欺负我不会拼contains吗?”回答正确。但是contains的实现是怎样的?不用看源码,先自己想一下有木有思路。
一个简单 ...
http://oj.leetcode.com/problems/implement-strstr/
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
大海捞针,很贴切,好吧,我用暴力居然直接过了,羞愧....
JDK源码中有实现,就不罗嗦了,下午研究了一下KMP算法(O(M + N)),很不错的算法,明天好好整理一下,重新写一遍,并写一篇关于KMP算法的博文吧。
暴力——O ...
新博文地址:[leetcode]Longest Palindromic Substring
http://oj.leetcode.com/problems/longest-palindromic-substring/
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.
返回字符串中最长的 ...
新博文地址[leetcode]3Sum Closest
http://oj.leetcode.com/problems/3sum-closest/
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exactly one solution. For exam ...
新博文地址:
[leetcode]3Sum
http://oj.leetcode.com/problems/3sum/
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c) must be in non-descending order. (ie, a ≤ b ...