File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change 1+ const fs = require ( "fs" ) ;
2+ const filePath = process . platform === "linux" ? "/dev/stdin" : "./서정우/input.txt" ;
3+ const input = fs
4+ . readFileSync ( filePath )
5+ . toString ( )
6+ . trim ( )
7+ . split ( "\n" )
8+ . map ( ( el ) => el . trim ( ) ) ;
9+
10+ const str1 = input [ 0 ] ;
11+ const str2 = input [ 1 ] ;
12+
13+ const set1 = str1 . split ( "" ) ;
14+ const set2 = str2 . split ( "" ) ;
15+
16+ const dp = Array ( set1 . length + 1 )
17+ . fill ( null )
18+ . map ( ( ) => Array ( set2 . length + 1 ) . fill ( 0 ) ) ;
19+
20+ let max = 0 ;
21+
22+ for ( let i = 1 ; i <= set1 . length ; i ++ ) {
23+ for ( let j = 1 ; j <= set2 . length ; j ++ ) {
24+ const char1 = set1 [ i - 1 ] ;
25+ const char2 = set2 [ j - 1 ] ;
26+
27+ if ( char1 === char2 ) {
28+ dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] + 1 ;
29+ max = Math . max ( dp [ i - 1 ] [ j - 1 ] + 1 , max ) ;
30+ } else {
31+ dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ;
32+ max = Math . max ( Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) , max ) ;
33+ }
34+ }
35+ }
36+
37+ console . log ( max ) ;
Original file line number Diff line number Diff line change 1- 5
1+ 선데이코딩
2+ 딩코이데선
You can’t perform that action at this time.
0 commit comments