We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6470428 commit 1659815Copy full SHA for 1659815
src/BullsAndCows.java
@@ -0,0 +1,16 @@
1
+public class BullsAndCows {
2
+ public static String getHint(String secret, String guess) {
3
+ int bulls = 0, cows = 0;
4
+ int[] count = new int[10];
5
+ for (int index =0 ; index < secret.length() ; index++) {
6
+ if (secret.charAt(index) == guess.charAt(index)) {
7
+ bulls++;
8
+ } else {
9
+ if (count[secret.charAt(index) - '0']++ < 0) cows++;
10
+ if (count[guess.charAt(index) - '0']-- > 0) cows++;
11
+ }
12
13
+
14
+ return bulls + "A" + cows + "B";
15
16
+}
0 commit comments