69. x 的平方根 非常简单的一个题,用二分法逼近求出ans即可,额外注意下溢出问题. 不过我要给自己增加难度,用long或者BigNum实现没意思,只能使用int类型 换句话当出现溢出时我们自己得检测出来 原代码(会溢出) class Solution { public int mySqrt(int x) { int l = 1; int r = x; while (l < r) { int mid = (l + r) / 2;// l+r会溢出 if (mid * mid == x) {
最近做了一道题目: Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note:Assume we are dealing with an environment which could only store intege
1.二维数组中的查找 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数. public class Solution { public boolean Find(int target, int [][] array) { if(array == null||array.length==0) return false; int rowIdx = 0,colIdx = array[0]