File tree 2 files changed +51
-0
lines changed
2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ //https://github.com/codeisneverodd/programmers-coding-test
2
+ //완벽한 정답이 아닙니다.
3
+ //정답 1
4
+ function solution ( w , h ) {
5
+ var answer = 1 ;
6
+ const gcd = greatestCommonDivisor ( w , h )
7
+ answer = w * h - ( h + w - gcd )
8
+ return answer ;
9
+ }
10
+
11
+ let greatestCommonDivisor = ( a , b ) => {
12
+ while ( b > 0 ) {
13
+ let r = a % b ;
14
+ a = b ;
15
+ b = r ;
16
+ }
17
+ return a ;
18
+ }
19
+ //정답 2
20
+ function solution ( w , h ) {
21
+ var answer = 1 ;
22
+ const gcd = greatestCommonDivisor ( w , h )
23
+ const erasedBoxInUnit = h / gcd + w / gcd - 1
24
+ answer = w * h - erasedBoxInUnit * gcd
25
+ return answer ;
26
+ }
27
+
28
+ let greatestCommonDivisor = ( a , b ) => {
29
+ while ( b > 0 ) {
30
+ let r = a % b ;
31
+ a = b ;
32
+ b = r ;
33
+ }
34
+ return a ;
35
+ }
Original file line number Diff line number Diff line change
1
+ //https://github.com/codeisneverodd/programmers-coding-test
2
+ //완벽한 정답이 아닙니다.
3
+ function solution ( record ) {
4
+ var answer = [ ] ;
5
+ const users = { }
6
+ record . map ( history => {
7
+ const [ action , id , name ] = history . split ( ' ' )
8
+ if ( action !== 'Leave' ) users [ id ] = name
9
+ } )
10
+ record . map ( history => {
11
+ const [ action , id , name ] = history . split ( ' ' )
12
+ if ( action === 'Enter' ) answer . push ( `${ users [ id ] } 님이 들어왔습니다.` )
13
+ if ( action === 'Leave' ) answer . push ( `${ users [ id ] } 님이 나갔습니다.` )
14
+ } )
15
+ return answer ;
16
+ }
You can’t perform that action at this time.
0 commit comments