Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d7a3f0d

Browse files
authoredJan 16, 2022
Create 2139-minimum-moves-to-reach-target-score.js
1 parent 40f8376 commit d7a3f0d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
 
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @param {number} target
3+
* @param {number} maxDoubles
4+
* @return {number}
5+
*/
6+
const minMoves = function(target, maxDoubles) {
7+
let count = 0;
8+
9+
while(target != 1){
10+
11+
if(target % 2 != 0){
12+
target--;
13+
count++;
14+
}
15+
else{
16+
if(maxDoubles != 0){
17+
target /= 2;
18+
count++;
19+
maxDoubles--;
20+
}
21+
else{
22+
count += target - 1;
23+
break;
24+
}
25+
}
26+
}
27+
return count;
28+
};

0 commit comments

Comments
 (0)
Please sign in to comment.