556. Next Greater Element III

PHOTO EMBED

Sat May 27 2023 10:30:08 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

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

    }
};
content_copyCOPY

https://leetcode.com/problems/next-greater-element-iii/description/