
LeetCode
文章平均质量分 67
NullPointExceptionc
只有知道自己有多菜,才会努力进步!
展开
-
LeetCode | Reverse Words in a String
题目:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".注意:通过从后向前遍历,遇到空格,就将后面的所有字符复制到StringBUffer中,并用一个int变量记录此次空格的原创 2015-08-08 14:02:44 · 323 阅读 · 0 评论 -
Copy List with Random Pointer
题目:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.思路:如图所示,直原创 2015-08-09 17:23:14 · 260 阅读 · 0 评论 -
LeetCode | Surrounded Regions
题目:Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X原创 2015-08-08 13:55:19 · 261 阅读 · 0 评论 -
二维数组顺时针打印
今天下午看到一题关于二维数组顺时针打印,感觉第二部的方法书中解释的有点脱离带水的意思,所以自己实现了一下,基本思想如下:其实题目就是安圈来一层一层的打印,所以每次圈的起点为二维数组对称轴上的数,并且由于每一圈的结束,二维数组的行和列的数是减二,所以结束条件就是:行package str;import java.util.Vector;public class PrintMatr原创 2015-10-20 16:05:12 · 827 阅读 · 1 评论 -
LeetCode : Restore IP Address_Jane
Question :Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111原创 2015-10-24 11:31:18 · 286 阅读 · 0 评论 -
LeetCode | Trapping Rain Water
题目:Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3原创 2015-10-09 16:58:08 · 248 阅读 · 0 评论 -
Java实现快速排序
今天特地把快速算法用Java实现了一下,毕竟找工作面试笔试用的比较多。package String.Cheng;import java.util.Scanner;public class QuickSort { public static void Swap(int []s,int l,int r){ int temp; if (s[l]<s[r]&&s[r]<s[(l+r)原创 2015-10-12 18:59:26 · 345 阅读 · 0 评论 -
求子数组中长度最长的子数组
这一题用动态规划的思想解决的,算法时间复杂度和空间复杂度都不太好,不过动态规划的思路基本都是这样的。如果求和最大字数组,同样可以对所有字数组进行叠加判断,不过最好在算法中改进一下,可以减少算法计算量。package text;import java.util.ArrayList;import java.util.Arrays;import java.util.List;/** * PD原创 2015-11-02 12:30:17 · 702 阅读 · 0 评论