C++ STL 2-line self-comment solution


  • 1
    L
    class Solution {
    public:
        int nextGreaterElement(int n) {
            string s = to_string(n);
            return next_permutation(s.begin(), s.end()) && stoll(s) <= numeric_limits<int>::max() ? stoi(s) : -1;
        }
    };
    

Log in to reply
 

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