码迷,mamicode.com
首页 >  
搜索关键字:solution upgrade    ( 13024个结果
11.5 排序后的字符串数组,其中散布着空字符串,编写一个方法,找出给定字符串的位置。
二分法变体,当查找到mid元素是空串时,同时向两边扩散寻找不为空串的索引作为mid,继续执行二分。public class Solution { public int search(String[] list, String str) { if (list == null || ...
分类:其他好文   时间:2014-08-24 14:09:32    阅读次数:149
Set Matrix Zeroes
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
9.11 给定一个布尔表达式,由0、1、&、|、^等符号组成,以及一个想要的布尔结果result,实现一个函数,算出有几种括号的放法可使该表达式得出result的值。
思路: 枚举分割点递归求解,可用DP优化。 注意递归终止条件。 注意 ^ & | 三种情况统计的不同。import java.util.HashMap;import java.util.Map;public class Solution { int countR(String terms,...
分类:其他好文   时间:2014-08-24 11:32:32    阅读次数:249
LeetCode "Maximal Rectangle"
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
9.5 确定某字符串的所有排列组合。
还是permutation的算法,字符串也没什么太大的区别。 先排序,然后注意如何去重。import java.util.ArrayList;import java.util.Arrays;public class Solution { public static ArrayList getP...
分类:其他好文   时间:2014-08-23 22:57:11    阅读次数:171
9.3 寻找magic index
在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
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.....
分类:其他好文   时间:2014-08-23 21:37:41    阅读次数:199
[LeetCode] Divide Two Integers( bit + 二分法 )
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-1之间double数字的二进制表示
思路:依次减去 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
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 c...
分类:其他好文   时间:2014-08-23 15:11:00    阅读次数:153
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!