Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Leetcode 113代码错误:第三个最大编号;代码给出错误的输出不知道为什么 您的输入产生了错误的输出。通过在调试器中单步执行指定输入的代码,这将使调试变得非常容易。使用将使这成为一个两行解决方案。请看该页底部的示例。 class Solution {_C++_Set - Fatal编程技术网

C++ Leetcode 113代码错误:第三个最大编号;代码给出错误的输出不知道为什么 您的输入产生了错误的输出。通过在调试器中单步执行指定输入的代码,这将使调试变得非常容易。使用将使这成为一个两行解决方案。请看该页底部的示例。 class Solution {

C++ Leetcode 113代码错误:第三个最大编号;代码给出错误的输出不知道为什么 您的输入产生了错误的输出。通过在调试器中单步执行指定输入的代码,这将使调试变得非常容易。使用将使这成为一个两行解决方案。请看该页底部的示例。 class Solution {,c++,set,C++,Set,Leetcode 113代码错误:第三个最大编号;代码给出错误的输出不知道为什么 您的输入产生了错误的输出。通过在调试器中单步执行指定输入的代码,这将使调试变得非常容易。使用将使这成为一个两行解决方案。请看该页底部的示例。 class Solution { public: int thirdMax(vector<int>& nums) { int n = nums.size(); set<int, greater<int&g

Leetcode 113代码错误:第三个最大编号;代码给出错误的输出不知道为什么
您的输入产生了错误的输出。通过在调试器中单步执行指定输入的代码,这将使调试变得非常容易。使用将使这成为一个两行解决方案。请看该页底部的示例。
class Solution {
public:
    int thirdMax(vector<int>& nums) {
        int n = nums.size();
        set<int, greater<int> > s;
        for(int i = 0; i<n; i++){
            s.insert(nums[i]);
        }
        n=s.size();
        set<int, greater<int> >::iterator iter = s.begin();
        if(n<3){
            advance(iter, n-1);
            return *iter;
        }else{
            advance(iter, n-3);
            return *iter;
        }
    }
};
Input: 2, 3, 1
Expected Output: 1
Code Output: 3