二分法变体,当查找到mid元素是空串时,同时向两边扩散寻找不为空串的索引作为mid,继续执行二分。public class Solution { public int search(String[] list, String str) { if (list == null || ...
分类:
其他好文 时间:
2014-08-24 14:09:32
阅读次数:
149
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.思路:使用两个向量分别记录每一行和每一列是否存在0。 1 class Solution { 2 public: 3...
分类:
其他好文 时间:
2014-08-24 12:49:02
阅读次数:
211
思路: 枚举分割点递归求解,可用DP优化。 注意递归终止条件。 注意 ^ & | 三种情况统计的不同。import java.util.HashMap;import java.util.Map;public class Solution { int countR(String terms,...
分类:
其他好文 时间:
2014-08-24 11:32:32
阅读次数:
249
My intuition is flood-fill the BFS solution, which is O(n^4); and then I figured out a DP solution which is O(n^4)..So I googled some hints: it can be...
分类:
其他好文 时间:
2014-08-24 09:08:32
阅读次数:
194
还是permutation的算法,字符串也没什么太大的区别。 先排序,然后注意如何去重。import java.util.ArrayList;import java.util.Arrays;public class Solution { public static ArrayList getP...
分类:
其他好文 时间:
2014-08-23 22:57:11
阅读次数:
171
在A[0..n-1]中,满足条件 A[i]==i的索引。给定一个有序数组,设法找到其中的magic index。扩展:考虑有重复元素的情况如何处理。public class Solution { public static int magicIndex(int[] array) { ...
分类:
其他好文 时间:
2014-08-23 22:47:51
阅读次数:
191
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.....
分类:
其他好文 时间:
2014-08-23 21:37:41
阅读次数:
199
Divide two integers without using multiplication, division and mod operator.常常出现大的负数,无法用abs()转换成正数的情况class Solution{private: vector f;public: in...
分类:
其他好文 时间:
2014-08-23 17:43:11
阅读次数:
215
思路:依次减去 0.5,0.25,0.125。。。 够减二进制为1,不够减二进制为0。public class Solution { public static String printBinary(double num) { if (num >= 1 || num 0) { ...
分类:
其他好文 时间:
2014-08-23 16:32:51
阅读次数:
182
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 c...
分类:
其他好文 时间:
2014-08-23 15:11:00
阅读次数:
153