forked from algorithm024/algorithm024
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTTTT.java
More file actions
39 lines (36 loc) · 1.04 KB
/
TTTT.java
File metadata and controls
39 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* @author JackWu
* @version 1.0
*/
public class TTTT {
public static void main(String[] args) {
Solution solution = new Solution();
int[] nums = new int[]{1,2,1};
int [] res = solution.nextGreaterElements(nums);
System.out.println(res);
}
static class Solution {
public int[] nextGreaterElements(int[] nums) {
if(nums == null || nums.length == 0) return new int[0];
int len = nums.length;
int[] result = new int[len];
for(int i = 0; i< nums.length; i++) {
int j = i + 1 == len ? 0 : i + 1;
int temp = -1;
while(j != i) {
if(nums[j] > nums[i]) {
temp = nums[j];
break;
}
j++;
if(j == len) j = 0;
}
result[i] = temp;
}
return result;
}
}
}