티스토리 뷰
Solution in JavaScript
const n = 5;
function utopianTree(n) {
let cycle = 1;
let height = 1;
while (cycle <= n){
if(cycle % 2 !== 0 ){ //홀수 즉, doubles its height in spring
height *= 2;
}else{
height++; //짝수. grows a meter in summer
}
cycle++;
}
console.log(height);
}
utopianTree(n);
찾고자하는 n까지의 cycle을 전부 condition에 맞게 구해야한다.
Spring은 값이 double이 되고 Summer는 값에 +1
Reference
www.hackerrank.com/challenges/utopian-tree/problem
'Algorithms' 카테고리의 다른 글
Beautiful Days at the Movies (0) | 2020.10.18 |
---|---|
Migratory Birds (0) | 2020.10.01 |
Electronics Shop (0) | 2020.09.25 |
The Hurdle Race (0) | 2020.09.25 |
Cats and a Mouse (0) | 2020.09.17 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- spring boot application
- substring()
- hackerrank javascript solution
- C++
- rest parameter
- math.max
- 프로그래머스 알고리즘문제
- math.abs
- hackerrank solution
- 프로그래머스 알고리즘
- 알고리즘
- easy javascript algorithm
- ... in Javascript
- code refactoring
- HackerRank Algorithm
- Object type casting
- algorithm
- Javascript Algorithm
- compareTo()
- java
- hackerrank
- equals()
- hackerrank javascript
- string class in java
- easy algorithm
- HashMap
- 프로그래머스
- javascript
- repeat()
- Collection Framework
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
글 보관함