首页 > 试题广场 >

下一个较大元素

[编程题]下一个较大元素
  • 热度指数:7007 时间限制:C/C++ 3秒,其他语言6秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解

给定一个int数组A及其大小n,返回一个int数组,int数组中的元素是原数组中每个元素比他大的下一个元素,若不存在则为-1。保证数组中元素均为正整数。

测试样例:
[11,13,10,5,12,21,3],7
返回:[13,21,12,12,21,-1,-1]
头像 黑眼X
发表于 2025-10-21 09:31:43
import java.util.*; public class NextElement { public int[] findNext(int[] A, int n) { if (n == 0 ) return A; if ( n == 1) ret 展开全文
头像 Dfine
发表于 2025-07-07 17:02:20
#include <stack> #include <vector> class NextElement { public: vector<int> findNext(vector<int> A, int n) { // w 展开全文