LeetCode(503)--下一个更大元素II
发布日期:2021-05-10 07:48:53 浏览次数:21 分类:精选文章

本文共 1833 字,大约阅读时间需要 6 分钟。

���������������

��������������������������������������������������������� II������������

1. ��������������� ������������������������������������������������������������������������������������������������������������������������������������������-1���

2. ��������������� ������������������������������������������������������������������������������������

3. ���������������

  • ������������������������������������������-1���
  • ���������������������������������������������������������������������������������������������������������������
  • ���������������������������

4. ���������������

class Solution {
public int[] nextGreaterElements(int[] nums) {
int[] result = new int[nums.length];
for (int i = 0; i < nums.length; i++) {
result[i] = -1;
}
for (int i = 0; i < nums.length; i++) {
int count = i + 1; //���������������i+1
while (count != i) {
if (count == nums.length) {
count = 0;
}
if (count == i) {
break; //������������������������
}
if (nums[count] > nums[i]) {
result[i] = nums[count];
break;
}
count++;
}
}
return result;
}
}

5. ��������������� ���������������[1,2,1]

  • ���������[2,-1,2]

6. ������������������

  • ������������������O(n��)������������������������������������
  • ������������������O(n)���������������������

7. ��������������� ������������������������������������������������������������������������������������������������������������������������������

8. ��������� ���������������������������������������������������������������������������������������������������������������������������������������������������������������

上一篇:mybatis使用时出现:对实体 “useSSL“ 的引用必须以 ‘;‘ 分隔符结尾问题的解决方法
下一篇:LeetCode(232)--用栈实现队列

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年04月26日 05时21分49秒