一、新语句
1.求绝对值 Math.abs(a-b)
double a =1.0;
double b = 0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1;
System.out.println(a==b);//false
System.out.println(Math.abs(a-b)<1e-6);//true
二、每日一练
题目
给定一个排序数组和一个目标值,在数组中找到目标值,并返回其索引。如果目标值不存在于数组中,返回它将会被按顺序插入的位置。
例子
解析
Java代码
class Solution {
public int searchInsert(int[] nums, int target) {
int temp = 0;
for(int i = 0; i < nums.length; i++) {
if (nums[i] == target) {
temp = i;
break;
} else if (nums[nums.length - 1] < target) {
temp = nums.length;
break;
} else if (nums[0] > target) {
temp = 0;
} else if(nums[i] > target) {
temp = i;
break;
}
}
return temp;
}
}