use STL next_permutation to solve


  • 0
    M

    class Solution {
    public:
    int nextGreaterElement(int n) {
    string t,s=to_string(n);
    t=s;
    next_permutation(s.begin(),s.end());
    if(s<=t) return -1;
    long num=stol(s);
    return num>INT_MAX? -1:num;
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.