
编程基础-分治
小郭不背锅
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 175 阅读 · 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 · 107 阅读 · 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 · 207 阅读 · 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 · 711 阅读 · 0 评论