https://leetcode-cn.com/problems/next-greater-element-ii/description/
class Solution {
public int[] nextGreaterElements(int []nums)
{
int res[]=new int[nums.length];
if(nums.length==0)
{
return res;
}
{
for(int i=0;i<nums.length;i++)
{
int temp=nums[i];
int flag=1;
for(int j=i+1;j<nums.length;j++)
{
if(nums[j]>temp)
{
res[i]=nums[j];
flag=0;
break;
}
}
if(flag==1)
{
for(int k=0;k<i;k++)
{
if(nums[k]>temp)
{
res[i]=nums[k];
flag=0;
break;
}
}
}
if(flag==1)
{
res[i]=-1;
}
}
}
return res;
}
}