https://oj.leetcode.com/problems/generate-parentheses/http://fisherlei.blogspot.com/2012/12/leetcode-generate-parentheses.htmlpublicclassSolution{
publicList<String>generateParenthesis(intn){
//SolutionB:
//returngenerateParenthesis_BruteForce(n);
..
分类:
其他好文 时间:
2015-01-02 16:12:32
阅读次数:
137
https://oj.leetcode.com/problems/implement-strstr/http://fisherlei.blogspot.com/2012/12/leetcode-implement-strstr.htmlpublicclassSolution{
publicintstrStr(Stringhaystack,Stringneedle){
//遍历haystack,对每一个字符,匹配needle
if(haystack==null||needle==nu..
分类:
其他好文 时间:
2015-01-02 16:12:25
阅读次数:
149
https://oj.leetcode.com/problems/swap-nodes-in-pairs/http://fisherlei.blogspot.com/2013/01/leetcode-swap-nodes-in-pairs.html/**
*Definitionforsingly-linkedlist.
*publicclassListNode{
*intval;
*ListNodenext;
*ListNode(intx){
*val=x;
*next=null;
*}
*}
*/
publ..
分类:
其他好文 时间:
2015-01-02 16:12:21
阅读次数:
151
https://oj.leetcode.com/problems/valid-parentheses/http://fisherlei.blogspot.com/2013/01/leetcode-valid-parentheses.htmlpublicclassSolution{
publicbooleanisValid(Strings)
{
if(s==null)
returntrue;
Stack<Character>stack=newStack<>();
for(charc:s..
分类:
其他好文 时间:
2015-01-02 16:12:14
阅读次数:
99
https://oj.leetcode.com/problems/remove-duplicates-from-sorted-array/http://fisherlei.blogspot.com/2012/12/leetcode-remove-duplicates-from-sorted.htmlpublicclassSolution{
publicintremoveDuplicates(int[]A){
if(A==null||A.length==0)
return0;//Invalidinput.
..
分类:
其他好文 时间:
2015-01-02 16:12:07
阅读次数:
118
https://oj.leetcode.com/problems/reverse-nodes-in-k-group/http://fisherlei.blogspot.com/2012/12/leetcode-reverse-nodes-in-k-group.html/**
*Definitionforsingly-linkedlist.
*publicclassListNode{
*intval;
*ListNodenext;
*ListNode(intx){
*val=x;
*next=null;
*}
..
分类:
其他好文 时间:
2015-01-02 16:12:00
阅读次数:
238
https://oj.leetcode.com/problems/merge-k-sorted-lists/http://fisherlei.blogspot.com/2012/12/leetcode-merge-k-sorted-lists.html/**
*Definitionforsingly-linkedlist.
*publicclassListNode{
*intval;
*ListNodenext;
*ListNode(intx){
*val=x;
*next=null;
*}
*}
*/
pu..
分类:
其他好文 时间:
2015-01-02 16:11:43
阅读次数:
152
https://oj.leetcode.com/problems/next-permutation/http://fisherlei.blogspot.com/2012/12/leetcode-next-permutation.htmlpublicclassSolution{
publicvoidnextPermutation(int[]num){
//SolutionB
nextPermutation_Math(num);
//SolutionA
//nextPermutation_AllPerms(..
分类:
其他好文 时间:
2015-01-02 16:11:11
阅读次数:
93
https://oj.leetcode.com/problems/remove-element/http://fisherlei.blogspot.com/2012/12/leetcode-remove-element.htmlpublicclassSolution{
publicintremoveElement(int[]A,intelem){
//Theordercanbechanged.
//Use2pointers.
//Onetoiteratethearray,
//Onetocopythelas..
分类:
其他好文 时间:
2015-01-02 16:10:11
阅读次数:
129
题目描述
长100厘米的细长直杆子上有n只蚂蚁。它们的头有的朝左,有的朝右。每只蚂蚁都只能沿着杆子向前爬,速度是1厘米/秒。当两只蚂蚁碰面时,它们会同时掉头往相反的方向爬行。这些蚂蚁中,有1只蚂蚁感冒了。并且在和其它蚂蚁碰面时,会把感冒传染给碰到的蚂蚁。
请你计算,当所有蚂蚁都爬离杆子时,有多少只蚂蚁患上了感冒。
输入
第一行输入一个整数n (1< n < 50),
表示蚂蚁的总数。...
分类:
其他好文 时间:
2015-01-02 16:06:38
阅读次数:
175