File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed
Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ //점프와 순간 이동
2+ function solution ( n )
3+ {
4+ var ans = 0 ;
5+ while ( n > 0 ) {
6+ if ( n % 2 == 0 ) {
7+ n = n / 2 ;
8+ }
9+ else {
10+ ans ++ ;
11+ n -- ;
12+ }
13+ }
14+ return ans ;
15+ }
Original file line number Diff line number Diff line change 1+ //영어 끝말잇기
2+ function solution ( n , words ) {
3+ var wordData = [ ] ; // 사용된 단어를 저장할 배열
4+ var order = 1 ; // 끝말잇기 순서
5+ var turns = 1 ; // 현재 차례의 사람
6+
7+ for ( var i = 0 ; i < words . length ; i ++ ) {
8+ // 현재 차례의 사람이 이전에 사용된 단어를 말한 경우
9+ if ( wordData . includes ( words [ i ] ) ||
10+ ( i > 0 && words [ i ] [ 0 ] !== words [ i - 1 ] [ words [ i - 1 ] . length - 1 ] ) ) {
11+ return [ turns , order ] ; // 탈락한 사람의 번호와 차례를 반환
12+ }
13+
14+ wordData . push ( words [ i ] ) ; // 단어를 사용된 단어 리스트에 추가
15+ turns ++ ; // 다음 차례의 사람으로 넘어감
16+
17+ // 모든 사람의 차례가 끝나면 다시 1번부터 시작
18+ if ( turns > n ) {
19+ turns = 1 ;
20+ order ++ ;
21+ }
22+ }
23+
24+ return [ 0 , 0 ] ;
25+ }
26+
Original file line number Diff line number Diff line change 1+ //카펫
2+ function solution ( brown , yellow ) {
3+ var total = brown + yellow ;
4+ for ( var i = 3 ; i <= Math . sqrt ( total ) ; i ++ ) {
5+ if ( total % i == 0 ) {
6+ var h = total / i ;
7+ var w = total / h ;
8+ if ( ( w - 2 ) * ( h - 2 ) == yellow ) {
9+ return [ h , w ] ;
10+ }
11+ }
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments