1 class Solution { 2 public: 3 vector<int> nextGreaterElements(vector<int>& nums) { 4 int count = nums.size(); 5 vector<int> temp(count, -1); 6 7 for (int i = 0; i < count; i++) 8 { 9 int target = nums[i]; 10 int j = (i + 1) % count; 11 while (j != i) 12 { 13 if (target < nums[j]) 14 { 15 temp[i] = nums[j]; 16 break; 17 } 18 j = (++j) % count; 19 } 20 } 21 return temp; 22 23 } 24 };