## 笔者解答1.1

``````class Solution {

public boolean canPlaceFlowers(int[] flowerbed, int n) {

int length=flowerbed.length;
boolean get_1=false;
for(int i=0;i<length;i++){

if(!get_1&&flowerbed[i]==0){

if(i==length-1){

n--;
get_1=true;
}else{

if(flowerbed[i+1]!=1){

n--;
get_1=true;
}
}
}else if(get_1){

if(flowerbed[i]==0){

get_1=false;
}
}else if(flowerbed[i]==1){

get_1=true;
}
}
System.out.println(n);
return n<=0;
}
}
``````

## 笔者分析1.2

``````class Solution(object):
def canPlaceFlowers(self, flowerbed, n):
tmp = [0]+flowerbed+[0]
for i in range(1, len(tmp)-1):
if tmp[i-1] == 0 and tmp[i] == 0 and tmp[i+1] == 0:
tmp[i] = 1  # 在 i 处栽上花
n -= 1
return n <= 0   # n 小于等于 0 ，表示可以栽完花

``````

## 笔者分析2.1

``````class Solution {

public int threeSumClosest(int[] nums, int target) {

Arrays.sort(nums);
int closestNum=nums[0]+nums[1]+nums[2];
int i;
for(i=0;i<nums.length-2;i++){

int mid=i+1;
int right=nums.length-1;
while(mid<right){

int sumthree=nums[i]+nums[mid]+nums[right];
if(Math.abs(closestNum-target)>Math.abs(sumthree-target)){

closestNum=sumthree;
}
if(sumthree<target){

mid++;
}else if(sumthree>target){

right--;
}else{

return target;
}
}
}
return closestNum;
}
}
``````