码迷,mamicode.com
首页 >  
搜索关键字:solution    ( 11547个结果
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 ...
分类:其他好文   时间:2014-05-17 11:30:21    阅读次数:247
Leetcode: Count and Say
一次过 1 public class Solution { 2 public String countAndSay(int n) { 3 if (n <= 0) return ""; 4 int i = 1; 5 String current ...
分类:其他好文   时间:2014-05-16 21:27:59    阅读次数:267
emacs quick open and jump file (or buffer) which name is current word
Sometime, we need to open a file or buffer which name began with current word in emacs. Here I give the solution as follows. (provide 'quick-file-jump) (defun ab/quick-buffer-jump () "Quickly jum...
分类:其他好文   时间:2014-05-15 15:02:20    阅读次数:373
Divide Two Integers
Divide two integers without using multiplication, division and mod operator. public class Solution { public int divide(int dividend, int divisor) { int sign = 1; if (dividend < 0) { ...
分类:其他好文   时间:2014-05-15 14:40:50    阅读次数:285
LeetCode Search in Rotated Sorted Array II
class Solution {public: bool search(int A[], int n, int target) { if (n A[mid]) { right = mid; sep = A[mid]; ...
分类:其他好文   时间:2014-05-15 09:29:52    阅读次数:177
leetcode第一刷_Count and Say
水题。 描述的还挺麻烦的,实际上就是纸老虎,用两个string,一个存上一轮的结果,一个用来更新出这一轮的结果,每次扫描上一轮,统计一个字符出现的次数,然后把这个次数和字符加入到这一轮的字符串中就可以了。 class Solution { public: string countAndSay(int n) { if(n == 0) return ""; ...
分类:其他好文   时间:2014-05-15 04:12:07    阅读次数:289
leetcode第一刷_Pow(x, n)
快速乘方的算法,写了好多变,出了各种错,真是服了我自己了。 思想是每次对n减半,将当前的temp平方。需要注意的是如果当前的n是个奇数,减半之后会丢失掉一次乘积,因此如果当前的n为奇数,应该先在结果里面乘一个temp。 还有,n可能是负数,负数的次方最后要求一次倒数。 class Solution { public: double pow(double x, int n) { ...
分类:其他好文   时间:2014-05-15 03:29:34    阅读次数:252
LeetCode Gas Station
class Solution {public: int canCompleteCircuit(vector &gas, vector &cost) { int len = gas.size(); if (len diff(len, 0); for (...
分类:其他好文   时间:2014-05-15 01:58:39    阅读次数:358
Leetcode: Unique Paths
这道题最开始采用recursive的方法,结果犯了TLE(time limit exceeded)的错误,事实证明recursive的时间代价还是太高,所以改用DP的方法,把曾经算出来的结果存起来,我用的是一个M*N的matrix来存储 1 public class Solution { 2 ...
分类:其他好文   时间:2014-05-14 10:57:31    阅读次数:245
LA 2038
Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he h...
分类:其他好文   时间:2014-05-14 00:29:42    阅读次数:251
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!