Java
文章平均质量分 59
qlv_Queen
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
最大公约数(Greatest Common Divisor)
求两个数的最大公约数,典型解法是辗转相除法,又叫欧几里得算法。原理:(m,n)表示m和n的最大公约数,且m>n。那么(m,n)=(n,m%n)=.....直到余数为0.代码如下:public class GCD { public static int gcd(int m, int n){ if(m*n<0){ return -1; } //辗转相除法原创 2014-07-15 14:22:49 · 2284 阅读 · 0 评论 -
最糟糕的编程面试题
今天早上看到一篇非常有意思的博客,博客原网址转载 2014-07-15 09:56:39 · 815 阅读 · 0 评论 -
最小公倍数(Least Common Multiple)
最小公倍数=两个数的乘积/两个数的最大公约数。接上篇求最大公约数方法,最小公倍数的代码如下:public class LCM { //最小公倍数=两数乘积/最大公约数 public static int lcm(int m, int n){ return m*n/GCD.gcd(m,n); } public static void main(String[] args){原创 2014-07-15 14:44:10 · 4767 阅读 · 1 评论 -
【递归】八皇后问题
public class EightQueen { static int columnForRow[] = new int [8]; public static boolean check(int row){ for(int i=0; i<row; i++){ int diff = Math.abs(columnForRow[row]-columnForRow[i]); if(原创 2014-07-09 15:13:03 · 631 阅读 · 0 评论 -
在一个升序的但是经过循环移动的数组中查找指定元素
数组是升序的,数组经过循环移动之后,肯定是有左半部分或者有半部分还是升序的。代码:public class SearchRotateArray { public static int search(int a[], int l, int u, int x) { while(l<=u){ int m = (l+u)/2; if(x==a[m]){ return m;原创 2014-07-10 16:06:35 · 2549 阅读 · 0 评论 -
【递归】输出给定的n对括号对的所有合法序列
类似这类题目想到用递归方法进行解决。jieti原创 2014-07-09 10:53:50 · 4575 阅读 · 3 评论 -
输出一个集合的所有子集合-Java代码实现(一)
找出一个集合的所有子集合,用排列组合的方式来解答ciwenti原创 2014-07-08 16:25:30 · 6007 阅读 · 0 评论 -
【递归】输出一个字符串的所有排列
字符串的排列问题:一个含有n个字符的字符串,求排列,假设yi原创 2014-07-08 17:19:47 · 1534 阅读 · 0 评论 -
输出一个集合的所有子集合-Java代码实现(二)
接上篇,提供另外一种解题s原创 2014-07-08 16:39:16 · 9532 阅读 · 0 评论 -
Bit Manipulation-计算一个整数中二进制中1的个数
整数zhopublic static int count1BitNumber(int n){int count = 0;while(n != 0){n>>=1;count += n&1;}return count;}原创 2014-07-03 10:59:11 · 937 阅读 · 2 评论 -
LeetCode Minimum Depth of Binary Tree
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { publi原创 2014-11-12 13:02:27 · 975 阅读 · 0 评论
分享