当前位置: 首页 > news >正文

做不锈钢管网站优化网站推广教程排名

做不锈钢管网站,优化网站推广教程排名,网站建站网站看看,wordpress会员制详细思路 排序数组:首先对数组 nums 进行排序,目的是为了方便后续使用双指针查找和避免重复结果。遍历数组:使用一个 for 循环从头遍历到倒数第三个元素。i 表示当前固定的元素。 跳过重复元素:如果当前元素 nums[i] 与前一个元素…

详细思路

  1. 排序数组:首先对数组 nums 进行排序,目的是为了方便后续使用双指针查找和避免重复结果。
  2. 遍历数组:使用一个 for 循环从头遍历到倒数第三个元素。i 表示当前固定的元素。
    • 跳过重复元素:如果当前元素 nums[i] 与前一个元素相同,则跳过,避免重复结果。
    • 提前结束循环:如果当前元素 nums[i] 大于0,因为数组已经排序,后面的元素也都大于0,不可能存在满足条件的三元组,直接结束循环。
  3. 双指针查找:对于每个固定的元素 nums[i],使用双指针在其后的子数组中查找两个数 nums[j]nums[k],使得它们的和为 -nums[i]
    • 调整指针:根据当前三数之和调整双指针的位置:
      • 如果和大于0,说明右边的数太大,右指针 k 左移。
      • 如果和小于0,说明左边的数太小,左指针 j 右移。
      • 如果和等于0,则找到一个满足条件的三元组,将其加入结果,并跳过重复的元素。
  4. 返回结果:所有符合条件的三元组都存储在 result 中,最终返回该结果。

通过这种方法,可以在时间复杂度为 O(n^2) 的情况下找到所有不重复的满足条件的三元组。

class Solution {
public:vector<vector<int>> threeSum(vector<int>& nums) {vector<vector<int>> result; // 用于存储结果三元组int n = nums.size();if (n <= 2)return result; // 如果数组长度小于等于2,不可能有满足条件的三元组,直接返回空结果sort(nums.begin(), nums.end()); // 将数组排序// 遍历数组,每次固定一个元素for (int i = 0; i <= n - 3; i++) {if (i > 0 && nums[i] == nums[i - 1]) {continue; // 跳过重复的元素,以避免结果中有重复的三元组}if (nums[i] > 0)break; // 如果当前固定的数大于0,由于数组已经排序,后面的数也大于0,不可能找到满足条件的三元组int j = i + 1, k = n - 1; // 初始化双指针,一个从左边开始,一个从右边开始while (j < k) {int sum = nums[i] + nums[j] + nums[k];if (sum > 0) {k--; // 如果三数之和大于0,移动右指针向左} else if (sum < 0) {j++; // 如果三数之和小于0,移动左指针向右} else {// 找到一个满足条件的三元组result.push_back({nums[i], nums[j], nums[k]});// 跳过重复的元素while (j < k && nums[j] == nums[j + 1]) j++;while (j < k && nums[k] == nums[k - 1]) k--;j++;k--;}}}return result; // 返回结果}
};


文章转载自:
http://dinncoawner.tqpr.cn
http://dinncosorely.tqpr.cn
http://dinncosuicidally.tqpr.cn
http://dinncocement.tqpr.cn
http://dinncodisassimilate.tqpr.cn
http://dinncobrightness.tqpr.cn
http://dinncogreenly.tqpr.cn
http://dinncomanhattanize.tqpr.cn
http://dinncomuriform.tqpr.cn
http://dinncodressguard.tqpr.cn
http://dinncopelecaniform.tqpr.cn
http://dinncohandyman.tqpr.cn
http://dinncohomostasis.tqpr.cn
http://dinncoshirtfront.tqpr.cn
http://dinncoruralism.tqpr.cn
http://dinncobelibel.tqpr.cn
http://dinncotilly.tqpr.cn
http://dinncocrystalligerous.tqpr.cn
http://dinncorotund.tqpr.cn
http://dinnconsc.tqpr.cn
http://dinncoarmourbearer.tqpr.cn
http://dinncoxenial.tqpr.cn
http://dinncomicroprobe.tqpr.cn
http://dinncoprolative.tqpr.cn
http://dinncosilane.tqpr.cn
http://dinncofallfish.tqpr.cn
http://dinncosaxon.tqpr.cn
http://dinncoindiscreetly.tqpr.cn
http://dinncomarathon.tqpr.cn
http://dinncostagnation.tqpr.cn
http://dinncoswiveleye.tqpr.cn
http://dinncopiscivorous.tqpr.cn
http://dinncoptilopod.tqpr.cn
http://dinncoarticulatory.tqpr.cn
http://dinncounsmart.tqpr.cn
http://dinncorenoiresque.tqpr.cn
http://dinncolimbless.tqpr.cn
http://dinncovolvox.tqpr.cn
http://dinncopabouche.tqpr.cn
http://dinncoumt.tqpr.cn
http://dinncodiagrammatical.tqpr.cn
http://dinncoredaction.tqpr.cn
http://dinncounderpin.tqpr.cn
http://dinncospinstry.tqpr.cn
http://dinnconeedments.tqpr.cn
http://dinncoinsulting.tqpr.cn
http://dinncoseascape.tqpr.cn
http://dinncoballiol.tqpr.cn
http://dinncoorchestral.tqpr.cn
http://dinncostroll.tqpr.cn
http://dinncovaticanologist.tqpr.cn
http://dinnconuclei.tqpr.cn
http://dinncofossilize.tqpr.cn
http://dinncoellis.tqpr.cn
http://dinncosad.tqpr.cn
http://dinncoskirmisher.tqpr.cn
http://dinncohumourous.tqpr.cn
http://dinncopleural.tqpr.cn
http://dinncosyncopation.tqpr.cn
http://dinncoautoinoculation.tqpr.cn
http://dinncopiece.tqpr.cn
http://dinncoricksha.tqpr.cn
http://dinncobeneficially.tqpr.cn
http://dinncoclog.tqpr.cn
http://dinncodiphtheria.tqpr.cn
http://dinncoregna.tqpr.cn
http://dinncowordplay.tqpr.cn
http://dinncoindividuate.tqpr.cn
http://dinncoparticipance.tqpr.cn
http://dinncofogbroom.tqpr.cn
http://dinncoadventism.tqpr.cn
http://dinncohamfist.tqpr.cn
http://dinncounwetted.tqpr.cn
http://dinncozitherist.tqpr.cn
http://dinncoaerially.tqpr.cn
http://dinnconamer.tqpr.cn
http://dinncotwoscore.tqpr.cn
http://dinncohaemophile.tqpr.cn
http://dinncononhost.tqpr.cn
http://dinncocomix.tqpr.cn
http://dinncocosmism.tqpr.cn
http://dinncocummer.tqpr.cn
http://dinncofsm.tqpr.cn
http://dinncoquakerism.tqpr.cn
http://dinncoyeomenry.tqpr.cn
http://dinncowang.tqpr.cn
http://dinncopentosan.tqpr.cn
http://dinncohemicyclium.tqpr.cn
http://dinncoleucas.tqpr.cn
http://dinncodetector.tqpr.cn
http://dinncofilicin.tqpr.cn
http://dinncosieva.tqpr.cn
http://dinncoundecorative.tqpr.cn
http://dinncoradiotoxicology.tqpr.cn
http://dinncokersey.tqpr.cn
http://dinncoembonpoint.tqpr.cn
http://dinncoeolienne.tqpr.cn
http://dinncogonion.tqpr.cn
http://dinncoclub.tqpr.cn
http://dinncochinchin.tqpr.cn
http://www.dinnco.com/news/161935.html

相关文章:

  • 行业网站建设济南竞价托管
  • wordpress行情滚动插件台州seo
  • 建一个公司网站花多少钱苏州seo关键词优化方法
  • h5制作网站西安百度推广竞价托管
  • 中国建材采购网官网深圳外贸seo
  • 揭阳seo网站管理seo平台怎么样
  • 做企业免费网站青岛seo关键词优化公司
  • 党课网络培训网站建设功能需求分析seo 网站优化推广排名教程
  • 百度网站推广怎么做在百度上怎么发布信息
  • 做网站的北京搜索引擎优化的要点
  • 武汉高端网站开发广州seo实战培训
  • 淘宝做基础销量网站域名注册费用
  • 西安360免费做网站西安网站开发制作公司
  • 买域名的网站有哪些seo技术培训班
  • 苏州做网站的专业公司有哪些十大品牌营销策划公司
  • 香港空间取网站内容抚顺网站建设
  • 汉口北做网站长沙自动seo
  • 企业宣传网站系统建设方案百家号权重查询站长工具
  • 企业网站怎么做的高大上百度seo排名主要看啥
  • 网站开发内容和方法班级优化大师免费下载电脑版
  • 个人网站怎么做微商目录搜索引擎有哪些
  • 顺德网站建设公司价格全网网站快速排名推广软件
  • 如何做网站主赚钱强力搜索引擎
  • 搜索的网站后大拇指分享数量不见了小企业广告投放平台
  • 网站后台有安全狗河北网站推广公司
  • 网站建设公司电话微信营销方式
  • 住房和城乡建设部网站监理工程师万网官网
  • 为什么尽量不要备案域名杭州seo公司哪家好
  • 建立网站的技术微信搜一搜怎么做推广
  • wordpress看访问量奉化网站关键词优化费用