Implement int sqrt(int x).
Compute and return the square root of x.
原题链接:https://oj.leetcode.com/problems/sqrtx/
使用二分法来解题。
public int sqrt(int x) {
if(x == 0 || x== 1)
return x;
in...
分类:
其他好文 时间:
2014-11-21 16:24:07
阅读次数:
175
#include #include using namespace std;int getO(string str,int &start,char ch){ int count=0; for(;start>str) { //char c = str.at(1); ...
分类:
其他好文 时间:
2014-11-20 23:25:07
阅读次数:
238
Given a list, rotate the list to the right by k places, where k is non-negative.
For example:
Given 1->2->3->4->5->NULL and k = 2,
return 4->5->1->2->3->NULL.
原题链接:https://oj.leetcode.com/proble...
分类:
其他好文 时间:
2014-11-20 13:46:09
阅读次数:
92
Maximum Tape Utilization Ratio(0594)Time limit(ms): 1000Memory limit(kb): 65535Submission: 467Accepted: 67Description设有n 个程序{1,2,…, n }要存放在长度为L的磁带上。程序...
分类:
其他好文 时间:
2014-11-19 23:32:37
阅读次数:
443
一道LeetCode OJ上的题目,要求设计一个LRU(Least Recently Used)算法,题目描述如下:Design and implement a data structure for Least Recently Used (LRU) cache. It should support...
分类:
编程语言 时间:
2014-11-19 13:51:25
阅读次数:
222
题目https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node/对每个节点递归。 1 /** 2 * Definition for binary tree with next pointer. 3 * .....
分类:
其他好文 时间:
2014-11-19 12:13:56
阅读次数:
154
Given an array of strings, return all groups of strings that are anagrams.
Note: All inputs will be in lower-case.
原题链接:https://oj.leetcode.com/problems/anagrams/
易位构词游戏的英文词汇是 anagram,这个词来源于有...
分类:
其他好文 时间:
2014-11-19 11:24:01
阅读次数:
170
Implement pow(x, n).
原题链接:https://oj.leetcode.com/problems/powx-n/
public double pow(double x, int n) {
if(n== 0)
return 1;
if(n == 1)
return x;
if(n % 2 ==0)
return pow(x*x,n/2);
...
分类:
其他好文 时间:
2014-11-19 11:19:53
阅读次数:
135
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41257397
今天OJ可好几次,发现总是出错,最后才发现是自己把题目理解错了,想想就觉得好笑。
题目的意思是给定一个整数n,让你求出按照上面规律在执行若干次后所得到的串,其实该算法主要用到递归的思想。
我却把题目意思错误地理解为:对于给定的整数n,对该整数n执行N次上述递归操作后得到的串。例如给定2,得到的结果是1112。
当我将给定整数设定为1000时,果断出现内...
分类:
其他好文 时间:
2014-11-19 11:18:20
阅读次数:
217
https://oj.leetcode.com/problems/binary-tree-level-order-traversal/ Given a binary tree, return the level order traversal of its nodes' values. (ie, f...
分类:
其他好文 时间:
2014-11-19 08:33:46
阅读次数:
179