二分法 java
static int erfen(int [] a,int n){
int hight = a.length;
int low = 1;
int mid = 1;
while(low<=hight){
mid = (low+hight)/2;
if(a[mid]>n) hight = mid-1;
else if(a[mid]<n)low = mid +1;
else return mid;
}
return -1; //根据题目可变
}
*****
这周做小组拉得题感觉有点小困难,反正就是做的可慢可慢,
周六周日去补题得时候发现,发现只要想通了,题还是比较容易得。
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
今天下午做题碰见得 ,我的思路需要去除首空格,
就在百度上查了下,字符串去除空格。
str.trim(); //去掉首尾空格
str.replace(" ",""); //去除所有空格,包括首尾、中间
str.replaceAll(" ", ""); //去掉所有空格,包括首尾、中间
str.replaceAll("\\s*", ""); //可以替换大部分空白字符, 不限于空格 ;
就这就这了。理发去了。