#include #include using namespace std; class Solution { public: vector nextGreaterElements(vector& nums) { vector ret; int ns = nums.size(); for (int i = 0; i < ns; i++){ int j; if (i < nums.size() - 1){ j = i + 1; } else { j = 0; } while (true){ if (nums[i] < nums[j]){ ret.push_back(nums[j]); break; } if (j < nums.size() - 1){ j++; } else { j = 0; } if (i == j){ ret.push_back(-1); break; } } } return ret; } }; int main() { // vector v = {1, 2, 3, 4, 3}; vector v = {1, 2, 1}; Solution s_1; vector vs = s_1.nextGreaterElements(v); for (auto array: vs){ cout << array << " "; } return 0; }