Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Leetcode Discuss Topic
- // https://leetcode.com/discuss/post/6691579/issue-with-recursion-and-stringstream-co-5z40/
- #include <bits/stdc++.h>
- using namespace std;
- void printLex(int n, string ans, vector<int> &result){
- stringstream ss(ans);
- int num;
- ss >> num;
- if(num > n){
- return;
- }
- cout << ans << '\n';
- if(num != 0){
- result.push_back(num);
- }
- for(int i = 0; i <= 9; i++){
- if(ans == "" && i == 0){
- continue;
- }
- else{
- char numberToChar = i + '0';
- printLex(n, ans + numberToChar, result);
- }
- }
- }
- int main() {
- // your code goes here
- int n;
- cin >> n;
- vector<int> result;
- printLex(n, "", result);
- cout << "Vector: " << '\n';
- for(int i : result){
- cout << i << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement