File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed
Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change 1+ var isValidSudoku = function ( board ) {
2+ for ( let i = 0 ; i < 9 ; i ++ ) {
3+ const set = new Set ( ) ;
4+ for ( let j = 0 ; j < 9 ; j ++ ) {
5+ if ( board [ i ] [ j ] !== "." ) {
6+ if ( set . has ( board [ i ] [ j ] ) ) {
7+ return false ;
8+ } else {
9+ set . add ( board [ i ] [ j ] ) ;
10+ }
11+ }
12+ }
13+
14+ const set2 = new Set ( ) ;
15+ for ( let j = 0 ; j < 9 ; j ++ ) {
16+ if ( board [ j ] [ i ] !== "." ) {
17+ if ( set2 . has ( board [ j ] [ i ] ) ) {
18+ return false ;
19+ } else {
20+ set2 . add ( board [ j ] [ i ] ) ;
21+ }
22+ }
23+ }
24+ }
25+
26+ for ( let i = 1 ; i <= 3 ; i ++ ) {
27+ for ( let j = 1 ; j <= 3 ; j ++ ) {
28+ const set = new Set ( ) ;
29+ for ( let k = 1 ; k <= 3 ; k ++ ) {
30+ const val1 = board [ i * 3 - k ] [ j * 3 - 3 ] ;
31+ const val2 = board [ i * 3 - k ] [ j * 3 - 2 ] ;
32+ const val3 = board [ i * 3 - k ] [ j * 3 - 1 ] ;
33+ if ( val1 !== "." && ! set . has ( val1 ) ) {
34+ set . add ( val1 ) ;
35+ } else if ( set . has ( val1 ) ) {
36+ return false ;
37+ }
38+ if ( val2 !== "." && ! set . has ( val2 ) ) {
39+ set . add ( val2 ) ;
40+ } else if ( set . has ( val2 ) ) {
41+ return false ;
42+ }
43+
44+ if ( val3 !== "." && ! set . has ( val3 ) ) {
45+ set . add ( val3 ) ;
46+ } else if ( set . has ( val3 ) ) {
47+ return false ;
48+ }
49+ }
50+ }
51+ }
52+ return true ;
53+ } ;
Original file line number Diff line number Diff line change 1+ /**
2+ * @param {string } s
3+ * @param {string } t
4+ * @return {boolean }
5+ */
6+ var isSubsequence = function ( s , t ) {
7+ let idx = 0 ;
8+ for ( let i = 0 ; i < t . length ; i ++ ) {
9+ if ( s [ idx ] === t [ i ] ) {
10+ idx ++ ;
11+ }
12+ }
13+ return idx === s . length ;
14+ } ;
You can’t perform that action at this time.
0 commit comments