Skip to content

Commit 0a74d4b

Browse files
authored
Update convert-integer-to-the-sum-of-two-no-zero-integers.cpp
1 parent edf6961 commit 0a74d4b

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

C++/convert-integer-to-the-sum-of-two-no-zero-integers.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@
44
class Solution {
55
public:
66
vector<int> getNoZeroIntegers(int n) {
7-
int curr = n;
87
string digits;
9-
while (curr) {
10-
if (curr % 10 == 0 ||
11-
(curr % 10 == 1 && curr != 1)) {
8+
for (int curr = n; curr; curr /= 10) {
9+
if (curr % 10 == 0 || (curr % 10 == 1 && curr != 1)) {
1210
digits.push_back('2');
1311
curr -= 10; // carry
1412
} else {
1513
digits.push_back('1');
1614
}
17-
curr /= 10;
1815
}
1916
reverse(digits.begin(), digits.end());
2017
int a = stoi(digits);

0 commit comments

Comments
 (0)