File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
66
66
| 207| [ Course Schedule] ( https://leetcode.com/problems/course-schedule/ ) | [ JavaScript] ( ./src/course-schedule/res.js ) | Medium|
67
67
| 210| [ Course Schedule II] ( https://leetcode.com/problems/course-schedule-ii/ ) | [ JavaScript] ( ./src/course-schedule-ii/res.js ) | Medium|
68
68
| 240| [ Search a 2D Matrix II] ( https://leetcode.com/problems/search-a-2d-matrix-ii/ ) | [ JavaScript] ( ./src/search-a-2d-matrix-ii/res.js ) | Medium|
69
+ | 299| [ Bulls and Cows] ( https://leetcode.com/problems/bulls-and-cows/ ) | [ JavaScript] ( ./src/bulls-and-cows/res.js ) | Medium|
69
70
| 307| [ Range Sum Query - Mutable] ( https://leetcode.com/problems/range-sum-query-mutable/ ) | [ JavaScript] ( ./src/range-sum-query-mutable/res.js ) | Medium|
70
71
| 310| [ Minimum Height Trees] ( https://leetcode.com/problems/minimum-height-trees/ ) | [ JavaScript] ( ./src/minimum-height-trees/res.js ) | Medium|
71
72
| 342| [ Power of Four] ( https://leetcode.com/problems/power-of-four/ ) | [ JavaScript] ( ./src/power-of-four/res.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {string } secret
3
+ * @param {string } guess
4
+ * @return {string }
5
+ */
6
+ var getHint = function ( secret , guess ) {
7
+ const arrLen = secret . length ;
8
+ let strA = 0 ;
9
+ let strB = 0 ;
10
+ let secMap = new Array ( 10 ) ;
11
+ let gueMap = new Array ( 10 ) ;
12
+
13
+ for ( let index = 0 ; index < arrLen ; index ++ ) {
14
+ if ( secret [ index ] === guess [ index ] ) {
15
+ strA ++ ;
16
+ } else {
17
+ const secNum = parseInt ( secret [ index ] ) ;
18
+ const guenum = parseInt ( guess [ index ] ) ;
19
+
20
+ ( secMap [ secNum ] ? secMap [ secNum ] += 1 : secMap [ secNum ] = 1 ) ;
21
+ ( gueMap [ guenum ] ? gueMap [ guenum ] += 1 : gueMap [ guenum ] = 1 ) ;
22
+ }
23
+ }
24
+
25
+ for ( let index = 0 ; index < 10 ; index ++ ) {
26
+ strB += ( secMap [ index ] && gueMap [ index ] && ( secMap [ index ] > gueMap [ index ] ? gueMap [ index ] : secMap [ index ] ) || 0 ) ;
27
+ }
28
+
29
+ // console.log(secMap, gueMap);
30
+
31
+ return `${ strA } A${ strB } B` ;
32
+ } ;
You can’t perform that action at this time.
0 commit comments