c 2b 2b convert vector of digits into integer

Solutions on MaxInterview for c 2b 2b convert vector of digits into integer by the best coders in the world

showing results for - "c 2b 2b convert vector of digits into integer"
Camille
03 Jan 2018
1// Convert integer to vector of digits
2vector<int> int_to_vector(long long n) { 
3    vector<int> vec;
4    while (n != 0) {
5        vec.push_back(n%10);
6        n /= 10;
7    }
8    reverse(vec.begin(), vec.end());
9    return vec;
10}
Anae
09 Jan 2020
1// Convert vector of digits to integer
2long long vector_to_int(vector<int> num) { 
3    long long n = 0;
4    int N = num.size();
5    for (int i = 0; i < N; i++) {
6        n += num[i]*pow(10, N-i-1);
7    }
8    return n;
9}