1365
本人思路
public int[] smallerNumbersThanCurrent(int[] nums) {
int length=nums.length;
int out[]=new int[length];
for(int i=0;i<length;i++){
for(int j=0;j<length;j++){
if(j==i)
continue;
if(nums[i]>nums[j])
out[i]++;
}
}
return out;
}
暴力排序 时间复杂度 N平方 空间复杂度1
优秀解
int n = nums.length;
int[] temp = new int[n];
temp = Arrays.copyOf(nums, n);
Arrays.sort(temp);
Map<Integer, Integer> map = new HashMap<>();
//排序后 k为 数组值 i为数组排在第几 即有几个比他小的
for(int i = 0; i < n; i++){
if(i == 0){
map.put(temp[i],0);
}else{
if(temp[i] > temp[i-1]){
map.put(temp[i],i);//如果i 与i-1不相等
}else{
map.put(temp[i],map.get(temp[i-1]));//如果相等 则向前取值
}
}
}
for(int i = 0; i < n; i++){
temp[i] = map.get(nums[i]);
}
return temp;
}
空间复杂度 sort方法 NlogN
1119
暴力破解
public String removeVowels(String S) {
char in[]=S.toCharArray();
StringBuffer sb=new StringBuffer();
for(int i=0;i<in.length;i++) {
if(in[i]=='a'||in[i]=='e'||in[i]=='i'||in[i]=='o'||in[i]=='u') {
continue;
}
sb.append(in[i]);
}
return sb.toString();
}
长度不可测 改进可用char数组代替sb 但是并无特优解
1761

被折叠的 条评论
为什么被折叠?



