用减法可能会超时,但可以用二分
class Solution {
public:
int divide(int d1, int d2) {// d1/d2
if(d1==0)
return 0;
if(d2==1)
return d1;
if(d2==-1)
...
分类:
其他好文 时间:
2014-06-29 07:22:02
阅读次数:
208
1、
??
Recover Binary Search Tree
Two elements of a binary search tree (BST) are swapped by mistake.
Recover the tree without changing its structure.
Note:
A solution using O(n) space is pretty...
分类:
其他好文 时间:
2014-06-20 10:13:49
阅读次数:
243
问题背景:
一直很想不通,公司花了N多钱请了一帮QlikView的Consultant做出来的solution竟然没有涉及Reload的部分,以至于每次刷新数据都需要刷新整个Data Model,之前和部门同事讨论的时候我还信誓旦旦的说QlikView就只能这样了,找不到方法只将新数据刷新到Data Model中而不用重新load之前已经在Memory里面的数据。
幸而今天一位朋友提到了Add...
分类:
其他好文 时间:
2014-06-20 09:12:58
阅读次数:
294
家中以前一直使用的电脑+矿机挖矿,电脑24小时开着不说,声音还特大;
前两天折腾了一把,将挖矿整体转到了树莓派上,而且整个都放到了书柜上。
世界一下子安静了(电表也安静了)~~~~树莓派开机后,先安装CGMiner的关联组件(已经先执行过Update & Upgrade操作) sudo
apt-ge...
分类:
其他好文 时间:
2014-06-13 14:23:29
阅读次数:
684
Givennpairs of parentheses, write a function to
generate all combinations of well-formed parentheses.For example, givenn= 3, a
solution set is:"((()))...
分类:
其他好文 时间:
2014-06-11 12:25:51
阅读次数:
239
第一种方法,用栈实现,最容易想到,也比较容易实现,每次碰到‘)’时update
max_len,由于要保存之前的‘(’的index,所以spacecomplexity 是O(n) 1 // 使用栈,时间复杂度 O(n),空间复杂度 O(n)
2 class Solution { 3 publ...
分类:
其他好文 时间:
2014-06-11 09:16:10
阅读次数:
197
原题地址:https://oj.leetcode.com/problems/powx-n/题意:Implement
pow(x,n).解题思路:求幂函数的实现。使用递归,类似于二分的思路,解法来自Mark Allen Weiss的《数据结构与算法分析》。代码:class
Solution: #...
分类:
编程语言 时间:
2014-06-11 08:59:33
阅读次数:
317
class Solution {public: char *strStr(char
*haystack, char *needle) { if (haystack == NULL || needle == NULL) return NULL;
int wpos[25...
分类:
其他好文 时间:
2014-06-11 07:40:05
阅读次数:
200
Given a singly linked list where elements are
sorted in ascending order, convert it to a height balanced BST.public class
Solution { /** Convert th...
分类:
其他好文 时间:
2014-06-10 00:22:44
阅读次数:
259
Given two integersnandk, return all possible
combinations ofknumbers out of 1 ...n.For example,Ifn= 4 andk= 2, a solution
is:[ [2,4], [3,4], [2,3],...
分类:
其他好文 时间:
2014-06-08 08:08:29
阅读次数:
294