码迷,mamicode.com
首页 >  
搜索关键字:cc150    ( 107个结果
9.1---上楼梯(CC150)
注意:错误主要在溢出问题上。所以不设置int,而是long。 public static int countWays(int n){ if(n == 1) return 1; if(n == 2) return 2; if(n == 3) re...
分类:其他好文   时间:2015-12-29 12:56:11    阅读次数:130
5.3---找最近的两个数(CC150)
public static int[] getCloseNumber(int x){ int[] res = new int[2]; int i = 1; int num = oneNumber(x); while(res[0] == ...
分类:其他好文   时间:2015-12-29 12:56:08    阅读次数:144
5.3(2)----机器人走方格2(CC150)
这道题只需要把障碍点都设为0就可以了。public static int countWays(int[][] map,int x, int y){ if( x < 0 || y < 0) return -1; int[][] dp = new int[x][y]; ...
分类:其他好文   时间:2015-12-29 12:51:49    阅读次数:143
4.9---二叉树路径和(CC150)
//注意,1,要判断null;2,要注意ArrayList直接复制会被一起改变。要通过new的方式来操作。public class Solution { public static void main(String[] args){ TreeNode root = new Tre...
分类:其他好文   时间:2015-12-28 14:03:33    阅读次数:117
7.2---蚂蚁相遇问题(CC150)
public class Ants { public double antsCollision(int n) { // write code here return (1 - Math.pow(0.5,n-1)); }}
分类:其他好文   时间:2015-12-25 10:07:09    阅读次数:183
4.6---找二叉树中序后继(CC150)
因为,没有重复值,所以只需要做一个标记就OK了。public class Successor { static boolean flag = false; static int result = 0; public int findSucc(TreeNode root, int...
分类:其他好文   时间:2015-12-22 23:08:10    阅读次数:368
4.5---判断是否是二叉排序树BST(CC150)
public boolean checkBST(TreeNode root) { return isBST(root, Long.MIN_VALUE, Long.MAX_VALUE); } public boolean isBST(TreeNode root, lo...
分类:编程语言   时间:2015-12-22 21:25:25    阅读次数:221
4.1---二叉树是否平衡(CC150)
//也就是把高度在递归过程中给一并算了。public class Balance { public static boolean checkBalance(TreeNode root, int[] dep){//java 里没有传地址if(null == root){dep[0] = 0;re...
分类:其他好文   时间:2015-12-22 14:34:10    阅读次数:167
3.7---猫狗收容所(CC150)
解答的思路:建立一个queue放狗,一个queue放猫。如下:import java.util.*;class Dog{ int time; int value; Dog(int a, int b){ time = a; value = b; }}...
分类:其他好文   时间:2015-12-21 23:26:24    阅读次数:174
3.5---用栈实现队列(CC150)
手写时候,别忘记import java.util.Stack;import java.util.Stack;class MyQueue { Stack s1 = new Stack(); Stack s2 = new Stack(); // Push element x to th...
分类:其他好文   时间:2015-12-21 12:37:23    阅读次数:149
107条   上一页 1 2 3 4 ... 11 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!