Algorithms - Guess
A small play and a small B Guess. Small B per 1, 2, 3 from a randomly selected, each time selecting a small A guess from 1, 2, 3. They conducted a total of three times in this game, return to the small A guessed a few times?
guess input array A small each guess, answer choices for each small array B. guess and 3 are equal to the length of the answer.
Example 1:
Input: guess = [1,2,3], answer = [1,2,3]
Output: 3
Explanation: A small every guess.
Example 2:
Input: guess = [2,2,3], answer = [3,2,1]
Output: 1
Explanation: A small only a second guess.
limit:
3 the length of the guess =
answer length = 3
guess element values {1, 2, 3} one.
answer element values {1,, one 23}.
Source: stay button (LeetCode)
class Solution {
public int game(int[] guess, int[] answer) {
int number = 0;
for(int i = 0; i<=2; i++){
if(guess[i] == answer[i]){
number++;
}
}
return number;
}
}