public class Program {
public static int[] Puzzle(int n) {
int[] test = new int[n];
for(int i=0; i<n; i++)
test[i]=i;
return test;
}
}
================================================
public class Program {
public static int[] Puzzle(int n) {
int[] test = new int[n];
for(int i=0; i<n; i++)
test[i] = i*n;
return test;
}
}
================================================
public class Program {
public static int[] Puzzle(int n) {
int[] test = new int[n];
for(int i=0; i<n; i++)
test[i] = i*i;
return test;
}
}
===============================================
public class Program {
public static int Puzzle(int[] v) {
int sum = 0;
for(int i=0;i < v.length; i++)
sum += v[i];
return sum;
}
}
================================================
public class Program {
public static int Puzzle(int n) {
int sum=0;
for(int i=0; i< n; i++)
sum += i*i;
return sum;
}
}
(系统显示还可以优化)
用平方和公式
===============================================
Rating 1:
public class Program {
public static int Puzzle(String s) {
int count =0;
for(int i=0;i<s.length();i++)
if(s.charAt(i)=='a')
count++;
return count;
}
}
有待优化
===============================================
Rating 2:
public class Program {
public static int Puzzle(String s, char x) {
int count=0;
for(int i=0; i<s.length();i++)
if(s.charAt(i)==x)
count++;
return count;
}
}
有待优化
================================================