Skip to content

Commit e04910e

Browse files
committed
Time: 2 ms (44%), Space: 58.3 MB (96%) - LeetHub
1 parent 396c94d commit e04910e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const decimalRepresentation = (n: number): number[] => {
2+
const base10Components: number[] = [];
3+
let positionalValue = 1; // Represents 10^0, 10^1, 10^2, etc.
4+
5+
while (n > 0) {
6+
const digit = n % 10;
7+
8+
// Only add non-zero digits as base-10 components
9+
if (digit !== 0) {
10+
const component = digit * positionalValue;
11+
base10Components.unshift(component);
12+
}
13+
14+
n = Math.floor(n / 10);
15+
positionalValue *= 10;
16+
}
17+
18+
return base10Components;
19+
};

0 commit comments

Comments
 (0)