Pow(x, n)Implement pow(x,n).按照定义做的O(n)肯定是TLE的。利用这个信息:x2n = (xn)2有个主意点,当n为负是,直接取反是不可行的。由于int的表示范围是[2-31, 231-1],当n为INT_MIN时,取反会溢出。因此需要对n==INT_MIN单独考虑。另...
分类:
其他好文 时间:
2014-12-13 13:26:21
阅读次数:
142
题目为:
Given an array of integers, every element appears twice except for one. Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without...
分类:
其他好文 时间:
2014-12-12 23:39:44
阅读次数:
473
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the...
分类:
系统相关 时间:
2014-12-12 01:11:43
阅读次数:
374
Try your best to provide an mechanism to implement what you want.1. All happen before compiling-time.1 QObject.connect(sender,SIGNAL(signal()), recive...
分类:
其他好文 时间:
2014-12-10 20:59:27
阅读次数:
350
标题Pow(x, n)通过率26.1%难度中等Implement pow(x,n). 以为只是单纯的求xn,习惯了用java里面的math.pow(x,n),所以我认为传进来的值都是比较正常的,谁知道竟然会传n<0的数。。。。。直接泪奔,然后再尝试。。。发现栈溢出,也就是说单纯的递归或者非递归针对....
分类:
其他好文 时间:
2014-12-10 17:47:13
阅读次数:
153
Spring bean 假设有如下类
public class Service implement IService{
@Transactional(readOnly = false, propagation=Propagation.REQUIRED)
public void methodA(){
.....
methodB()
......
...
分类:
编程语言 时间:
2014-12-09 21:28:23
阅读次数:
278
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
int i,j,k;
if(needle[0]=='\0') return 0;
for(i=0;haysta...
分类:
其他好文 时间:
2014-12-09 15:48:41
阅读次数:
113
设计并实现最近最久未使用(Least Recently Used)缓存。链接:https://oj.leetcode.com/problems/lru-cache/题目描述:Design and implement a data structure for Least Recently Used (...
分类:
系统相关 时间:
2014-12-09 15:32:34
阅读次数:
320
题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2054这题只要处理小数点后面无效的'0'或'.' strstr()函数是两个字符串 需用“”号代码#include#includechar a[100000],b[100000];void chu_li(....
分类:
其他好文 时间:
2014-12-08 17:05:22
阅读次数:
164
问题描述:
Implement pow(x, n).
基本思想:
将求幂转换为求对数的幂 . 如x^n = exp(n*log(x));
代码:
double pow(double x, int n) { //C++
if(x == 0.0)
return 0;
if(n == 0)
return ...
分类:
其他好文 时间:
2014-12-07 15:05:48
阅读次数:
145