forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_299.java
24 lines (23 loc) · 833 Bytes
/
_299.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.fishercoder.solutions;
public class _299 {
public static class Solution1 {
public String getHint(String secret, String guess) {
int[] secretCows = new int[10];
int[] guessCows = new int[10];
int bulls = 0;
for (int i = 0; i < secret.length(); i++) {
if (guess.charAt(i) == secret.charAt(i)) {
bulls++;
} else {
secretCows[Character.getNumericValue(secret.charAt(i))]++;
guessCows[Character.getNumericValue(guess.charAt(i))]++;
}
}
int cows = 0;
for (int i = 0; i < 10; i++) {
cows += Math.min(secretCows[i], guessCows[i]);
}
return bulls + "A" + cows + "B";
}
}
}