随笔分类 - 算法实现
贴出代码
摘要:public class Solution { public void merge(int A[], int m, int B[], int n) { int a=m-1; int b=n-1; int index=m+n-1; whil...
阅读全文
摘要:使用最简单的排序方法; 1 /** 2 * Definition for an interval. 3 * public class Interval { 4 * int start; 5 * int end; 6 * Interval() { start = 0;...
阅读全文
摘要:https://oj.leetcode.com/problems/valid-parentheses/遇到左括号入栈,遇到右括号出栈找匹配,为空或不匹配为空,public class Solution { public boolean isValid(String s) { ch...
阅读全文
摘要:结构模式:将类和对象结合在一起构成更大的结构,就像是搭积木。1.适配器模式源接口---适配器--目标接口2.使用场景:现在你有一个很古老的类,里面的一些方法很有用,你如何使用这些方法?当然你可以new 一个对象直接访问,但是,我们现在需要使用新的接口。比如:Old类实现了两个很牛逼的功能,class...
阅读全文
摘要:大道至简http://blog.csdn.net/hguisu/article/details/79697571、map的输入key: 文档 id value: 文档内容输出:key 词:文档idvalue 12.combine输入 key list输出: key: 词 value: 文档i...
阅读全文
摘要:刚才写了k个,顺手写个2个的,在链表的归并排序中很有用,效率非常好 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next;...
阅读全文
摘要:1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * ...
阅读全文
摘要:1.超时的,效率太低 1 public class Solution { 2 public int jump(int[] A) { 3 int len=A.length; 4 int d[]=new int[len]; 5 d[0]=0; 6 ...
阅读全文
摘要:1。第一次觉得很简单,但是超时了 1 public class Solution { 2 public boolean canJump(int[] A) { 3 4 int len=A.length; 5 boolean b[]=new bo...
阅读全文
摘要:1 public class Solution { 2 public int firstMissingPositive(int[] A) { 3 HashSet hash=new HashSet(); 4 int count=0; 5 int...
阅读全文
摘要:参考https://oj.leetcode.com/problems/distinct-subsequences动态规划方程dp[i][j]=dp[i-1][j-1]+dp[i-1][j] (s(i)==t(i))dp[i][j]=dp[i-1][j];边界条件: iif(j==0) d[i][j]...
阅读全文
摘要:1 public class Solution { 2 public String get(String a,String b) 3 { 4 5 if(a==""||b=="") return ""; 6 int len1=a.le...
阅读全文
摘要:1.从外围搜索O,深度搜索出现了Line 35: java.lang.StackOverflowErrorLast executed input:["OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO 1 public class Solution { 2...
阅读全文
摘要:stl 中的下一个排列在写一遍忘了写个1个多小时,使用递归写的,错误就在我使用一个list保存当前剩下的数,然后利用k/(n-1)!的阶乘就是删除的数字,但进过观察,比如 list={1,2,3}分成3组:1 {2,3}2 {1,3}3 {1,2}确定位于哪个组,然后确定位于哪个组的第几个nyoj ...
阅读全文
摘要:1.枚举法(超时) 1 public class Solution { 2 public int largestRectangleArea(int[] height) { 3 int max=-1; 4 for(int i=0;i=0&&height[k] s...
阅读全文
摘要:https://oj.leetcode.com/problems/add-binary/ 实” 1 public class Solution { 2 public String addBinary(String a, String b) { 3 char c1[]=a....
阅读全文
摘要:首先,我们要知道set是利使用map是实现的,因为只要利用map中的key唯一性就行了。1.hashmap 和hashtable的区别是什么?我们可以背出: hashtable线程安全。hashmap不安全。 hashmap中key 和value可以为空,当然根据唯一性,只能有一个key为null;...
阅读全文
摘要:java: http://my.oschina.net/xianggao/blog/88477锁的学习 NLP: http://52opencourse.com/138/斯坦福大学自然语言处理第五课-拼写纠错(spelling-correction) http://mallet.cs.umass.e
阅读全文
摘要:/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; ...
阅读全文
摘要:http://blog.csdn.net/pickless/article/details/9191075Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e.,0 1 2 4 5 6 7migh...
阅读全文

浙公网安备 33010602011771号