File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ package easy ;
2
+
3
+ import java .util .HashSet ;
4
+ import java .util .Set ;
5
+
6
+ public class BullsandCows {
7
+
8
+ public String getHint (String secret , String guess ) {
9
+ int [] secretCows = new int [10 ];
10
+ int [] guessCows = new int [10 ];
11
+ int bulls = 0 ;
12
+ for (int i = 0 ; i < secret .length (); i ++){
13
+ if (guess .charAt (i ) == secret .charAt (i )) bulls ++;
14
+ else {
15
+ secretCows [Character .getNumericValue (secret .charAt (i ))] ++;
16
+ guessCows [Character .getNumericValue (guess .charAt (i ))] ++;
17
+ }
18
+ }
19
+ int cows = 0 ;
20
+ for (int i = 0 ; i < 11 ; i ++){
21
+ cows += Math .min (secretCows [i ], guessCows [i ]);
22
+ }
23
+ return bulls + "A" + cows + "B" ;
24
+ }
25
+
26
+ }
Original file line number Diff line number Diff line change 18
18
|325|[ Maximum Size Subarray Sum Equals k] ( https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/ ) |[ Solution] | O(n)|O(n) | Medium| HashMap
19
19
|314|[ Binary Tree Vertical Order Traversal] ( https://leetcode.com/problems/binary-tree-vertical-order-traversal/ ) |[ Solution] ( ../../blob/master/MEDIUM/src/medium/BinaryTreeVerticalOrderTraversal.java ) | O(n)|O(n) | Medium| HashMap, BFS
20
20
|301|[ Remove Invalid Parentheses] ( https://leetcode.com/problems/remove-invalid-parentheses/ ) |[ Solution] | ? | ? | Hard| BFS
21
+ | 299| [ Bulls and Cows] ( https://leetcode.com/problems/bulls-and-cows/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/BullsandCows.java ) | O(n)| O(1) | Easy|
21
22
| 292| [ Nim Game] ( https://leetcode.com/problems/nim-game/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/NimGame.java ) | O(1)| O(1) | Easy|
22
23
| 283| [ Move Zeroes] ( https://leetcode.com/problems/move-zeroes/ ) | [ Solution] ( ../../blob/master/EASY/src/easy/MoveZeroes.java ) | O(n)| O(1) | Easy|
23
24
| 280| [ Wiggle Sort] ( https://leetcode.com/problems/wiggle-sort/ ) | [ Solution] ( ../../blob/master/MEDIUM/src/medium/WiggleSort.java ) | O(n)| O(1) | Medium|
You can’t perform that action at this time.
0 commit comments