Skip to content

Commit 65f01f4

Browse files
committed
practice to solve no.2553
1 parent 85d4682 commit 65f01f4

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

javascript/index.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,4 +1403,36 @@ var maximumOddBinaryNumber = function(s) {
14031403
let s = "010";
14041404
// Output: "001"
14051405
// Explanation: Because there is just one '1', it must be in the last position. So the answer is "001".
1406-
// console.log(maximumOddBinaryNumber(s));
1406+
// console.log(maximumOddBinaryNumber(s));
1407+
1408+
/**
1409+
* 2553. Separate the Digits in an Array
1410+
*
1411+
* @param {number[]} nums
1412+
* @return {number[]}
1413+
*/
1414+
var separateDigits = function(nums) {
1415+
/*
1416+
將參數元素依照位數拆開之後依照原本的順序合併
1417+
*/
1418+
let ans = [];
1419+
for(let i = 0;i < nums.length;++i) {
1420+
while(nums[i] > 0){
1421+
ans.push(nums[i] % 10);
1422+
nums[i]/=10;
1423+
}
1424+
}
1425+
console.log(ans);
1426+
1427+
};
1428+
let nums = [13,25,83,77];
1429+
/*
1430+
Output: [1,3,2,5,8,3,7,7]
1431+
Explanation:
1432+
- The separation of 13 is [1,3].
1433+
- The separation of 25 is [2,5].
1434+
- The separation of 83 is [8,3].
1435+
- The separation of 77 is [7,7].
1436+
answer = [1,3,2,5,8,3,7,7]. Note that answer contains the separations in the same order.
1437+
*/
1438+
console.log(separateDigits(nums));

0 commit comments

Comments
 (0)