1.x的平方根 java (1)直接使用函数 class Solution { public int mySqrt(int x) { int rs = 0; rs = (int)Math.sqrt(x); return rs; } } (2)二分法 对于一个非负数n,它的平方根不会小于大于(n/2+1). 在[0, n/2+1]这个范围内可以进行二分搜索,求出n的平方根. class Solution { public int mySqrt(int x) { long left=1,right=
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目前提条件:让你输入一个数组,包含一个起点S,一个终点D,一个时间T.(其中X代表墙,.代表此地可行.) 题目要求:在规定的第T秒,问你是否能够走出迷宫.(每走一步耗时1s). 解题方法:DFS+vis[][]+flag+(新技巧)奇偶剪枝. #include<iostream> #include<string.h> #include<cmath>; using n
NodeTree类 public class NodeTree { private int num; private NodeTree left; private NodeTree right; public int getNum() { return num; } public void setNum(int num) { this.num = num; } public NodeTree getLeft() { return left; } public void setLeft(NodeT
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive integer. Example 1: Input: 2 Output: 2 Explanation:
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive integer. Example 1: Input: 2 Output: 2 Explanation: