First, select the map
1.
Resolution:
2.
Resolution:
Answer: 14 (interference terms: 1001312)
fun1 (xyz) pass by reference, the value itself is changed.
fun2 (abc) passed by value, parameter change is no effect argument.
abc xyz is assigned, the value 14
3.
Resolution:
A option, occurs when the nested loops, the number of layers is not specified; C options, when nested loops, does not require to be retracted when the writing of code; D option, the expression in parentheses for statement can be omitted . So B option right
4.
5.
Resolution:
According to the meaning of problems between the two groups is already sorted, just sort of elements within the group can be.
The set of k elements of Comparative sort, the lower bound of the time O (klog2k), a total of n / k groups, i.e. O (klog2k * n / k) = O (nlog2k).
6.
7.
8.
Parsing: B items were reversed
9.
10.
11.
Second, the programming problem
import java.util.Arrays;
class Solution1313 {
public static void main(String[] args){
int[] nums={1,2,3,4};
int[] res=decompressRLElist(nums);
System.out.println(Arrays.toString(res));
}
public static int[] decompressRLElist(int[] nums) {
int len=0;
//遍历偶数角标 累加得到新数组的长度
for(int i=0;i<nums.length;i+=2){
len+=nums[i];
}
int[] res=new int[len];
//遍历奇数角标 获取需要被多次写入的数据
//1 2 3 4
//2 4 4 4
int index=0;
for(int i=1;i<=nums.length;i+=2){
for(int j=0;j<nums[i-1];j++){
res[index++]=nums[i];
}
}
return res;
}
}
class Solution {
public int findNumbers(int[] nums) {
int c=0;
for(int i=0;i<nums.length;i++){
if((nums[i]>=10&&nums[i]<=100)||(nums[i]>=1000&&nums[i]<=10000)){
c++;
}
}
return c;
}
}
class Solution {
public int[] sortArrayByParity(int[] A) {
int[] B = new int[A.length];
int left = 0;
int right=B.length-1;
for(int i=0;i<A.length;i++){
if(A[i]%2==0){
B[left++]=A[i];
}else{
B[right--]=A[i];
}
}
return B;
}
}
class Solution {
public int majorityElement(int[] nums) {
Arrays.sort(nums);
int m = 0;
int mcount=0;
for(int i=0;i<nums.length;){
if(i>nums.length/2){
break;
}
int count=1;
for(int j=i+1;j<nums.length;j++){
if(nums[j]==nums[i]){
count++;
}else{
break;
}
}
if(count>mcount){
mcount=count;
m=nums[i];
}
i+=count;
}
return m;
}
}