![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
编程基础-分治
小郭不背锅
这个作者很懒,什么都没留下…
展开
-
sqrtx
题目描述Implementint sqrt(int x).Compute and return the square root of x.二分法:public class Solution { public int sqrt(int x) { if(x<2)return x; int left = 1; int right =x; while(tr...原创 2018-04-11 10:10:29 · 146 阅读 · 0 评论 -
powx-n
题目描述Implement pow(x, n).这是用递归减少循环次数public class Solution { public double pow(double x, int n) { if(n==0)return 1; if(n<0)return (1/x)*pow(1/x,-(n+1)); if(n%2==0)return pow(x*x,n/2...原创 2018-04-11 10:32:24 · 81 阅读 · 0 评论 -
restore-ip-addresses
题目描述Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given"25525511135",return["255.255.11.135", "255.255.111.35"]. (Order d...原创 2018-04-11 14:45:27 · 162 阅读 · 0 评论 -
无序数组中最小的k个数
题目描述对于一个无序数组,数组中元素为互不相同的整数,请返回其中最小的k个数,顺序与原数组中元素顺序一致。给定一个整数数组A及它的大小n,同时给定k,请返回其中最小的k个数。测试样例:[1,2,4,3],4,2返回:[1,2]y用Collections.sort和Comparator去做即可。这里对HashMap的键值对排序,因为hashMap中装的是EnteySet<K,V&...原创 2018-04-11 15:19:20 · 640 阅读 · 0 评论