I, entitled 1
Second, the idea
Third, the code
public class LCP_1 {
public static void main(String[] args) {
//实例1 输出结果为3
// int[] guess = {1,2,3};
// int[] answer = {1,2,3};
// System.out.println( game( guess, answer ));
//实例2 输出结果为1
int[] guess = {2,2,3};
int[] answer = {3,2,1};
System.out.println( game( guess, answer ));
}
public static int game(int[] guess, int[] answer) {
int result = 0;
for( int i = 0; i < guess.length; i++ ){
if( guess[i] == answer[i] )
result++;
}
return result;
}
}
: Power button (LeetCode)
link: https: //leetcode-cn.com/problems/guess-numbers
copyrighted by deduction from all networks. Commercial reprint please contact the authorized official, non-commercial reprint please indicate the source. ↩︎