Skip to content

Commit 628aab4

Browse files
authored
Create 1523-count-odd-numbers-in-an-interval-range.js
1 parent 6053402 commit 628aab4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number} low
3+
* @param {number} high
4+
* @return {number}
5+
*/
6+
const countOdds = function(low, high) {
7+
let res = 0
8+
9+
const odd = num => num % 2 === 1
10+
if(odd(low)) res++
11+
12+
const num = Math.floor( (high - low) / 2 )
13+
res += num
14+
15+
if(high > low + 2 * num && odd(high)) res++
16+
17+
return res
18+
};

0 commit comments

Comments
 (0)