题库 C++/C语言题库 题目列表 给定一个整数数组nums,找到其中最长的严格上升子序列...
单选题

给定一个整数数组nums,找到其中最长的严格上升子序列的长度。 

子序列是指从原数组中删除一些元素(或不删除)后,剩余元素保持原有顺序的序列。 

该程序的时间复杂度为()

1 #include <iostream> 
2 #include <vector> 
3 #include <algorithm> 
4 using namespace std; 
5
6 int lengthOfLIS(vector<int>& nums) { 
7  int n = nums.size(); 
8  if (n == 0) return 0; 
9  vector<int> dp(n, 1); 
10
11  for (int i = 1; i < n; i++) { 
12   for (int j = 0; j < i; j++) { 
13    if (nums[i] > nums[j]) { 
14     _________________________ 
15    } 
16   } 
17  }
18  return *max_element(dp.begin(), dp.end()); 
19 } 
20
21 int main() { 
22  int n; 
23  cin >> n; 
24  vector<int> nums(n); 
25  for (int i = 0; i < n; i++) { 
26   cin >> nums[i]; 
27  } 
28
29  int result = lengthOfLIS(nums); 
30  cout << result << endl; 
31
32  return 0; 
33 }


A.

O(n2)

B.

O(n)

C.

O(log(n))

D.

O(nlog(n))

题目信息
2025年 七级 选择题
-
正确率
0
评论
41
点击