您现在的位置是:主页 > news > 256Mb wordpress/seo如何快速排名百度首页

256Mb wordpress/seo如何快速排名百度首页

admin2025/6/17 9:45:09news

简介256Mb wordpress,seo如何快速排名百度首页,做网络推广教程,做网站的颜色搭配思路&#xff1a;哈希表 1.使用set去重。 2.逮着一个数一直while到以该数为头的最长连续序列的最大长度。 3.使用变量记录最大值并返回 class Solution { public:int longestConsecutive(vector<int>& nums) {unordered_set<int> num_set;for (const int&…

256Mb wordpress,seo如何快速排名百度首页,做网络推广教程,做网站的颜色搭配思路&#xff1a;哈希表 1.使用set去重。 2.逮着一个数一直while到以该数为头的最长连续序列的最大长度。 3.使用变量记录最大值并返回 class Solution { public:int longestConsecutive(vector<int>& nums) {unordered_set<int> num_set;for (const int&…

在这里插入图片描述

思路:哈希表

1.使用set去重。
2.逮着一个数一直while到以该数为头的最长连续序列的最大长度。
3.使用变量记录最大值并返回

class Solution {
public:int longestConsecutive(vector<int>& nums) {unordered_set<int> num_set;for (const int& num : nums) {//去重num_set.insert(num);}int longestStreak = 0;for (const int& num : num_set) {if (!num_set.count(num - 1)) {int currentNum = num;int currentStreak = 1;while (num_set.count(currentNum + 1)) {currentNum += 1;currentStreak += 1;}longestStreak = max(longestStreak, currentStreak);}}return longestStreak;           }
};