Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5d398d0

Browse files
Merge pull requestneetcode-gh#2822 from chetannada/ltc-1688-js
Create 1688-count-of-matches-in-tournament.js
2 parentsf90ebe4 +e95f84b commit5d398d0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
*@param {number} n
3+
*@return {number}
4+
*/
5+
varnumberOfMatches=function(n){
6+
letmatches=0;// initialize matches to zero
7+
letnum=n;// initialize num equal to n
8+
for(leti=0;i<n;i++){// loop through the number n
9+
if(num==1){// if num is equal to 1 then break the for loop
10+
break;
11+
}else{// else
12+
if(num%2==0){// if num is even
13+
letdivide=num/2;// divide num by 2
14+
matches+=divide;// add divide to matches
15+
num-=divide;// subtract divide to num
16+
}else{// else
17+
letdivide=(num-1)/2;// subtract num by 1 and then divide it by 2
18+
matches+=divide;// add divide to matches
19+
num-=divide;// subtract divide to num
20+
}
21+
}
22+
}
23+
returnmatches;// return number matches
24+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp