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

小说wordpress主题进一步优化落实

小说wordpress主题,进一步优化落实,如何做网站个人,没有面板的服务器怎么建设网站本篇文章继续和大家一起刷算法题 第一题 题目链接 . - 力扣(LeetCode) 题目解析 题目要求: 这是一个连续的子数组 计算子数组内元素的和,若数组内元素的和符合 > target的值并且该子数组的长度是最短的,则返回…

本篇文章继续和大家一起刷算法题

第一题

题目链接

. - 力扣(LeetCode)

题目解析

 题目要求:

这是一个连续的子数组

计算子数组内元素的和,若数组内元素的和符合 >= target的值并且该子数组的长度是最短的,则返回该长度

代码原理

原理一:暴力枚举

原理二:滑动窗口

代码编写

对应原理一

class Solution {

public:

    int minSubArrayLen(int target, vector<int>& nums) {

        int len = INT_MAX;

        for(int left = 0; left < nums.size(); left++)

        {

            int sum = 0;

            for(int right = left; right < nums.size(); right++)

            {

                sum += nums[right];

                if(sum >= target)

                {

                    len = min(len, right - left + 1);

                    break;

                }

            }

        }

        if(len == INT_MAX)

        {

            len = 0;

        }

        return len;

    }

};

这里值得注意的是暴力枚举会超过时间限制,但并不是说这种方法是错误的

对应原理二

class Solution {

public:

    int minSubArrayLen(int target, vector<int>& nums) {

        int left = 0, right = 0, sum = 0, len = INT_MAX;

    while(right < nums.size())

    {

        sum += nums[right];//进窗口

        while(sum >= target)//判断

        {//4

            len = min(len, right + 1 - left);//更新结果

            sum -= nums[left++];//出窗口

        }

            right++;    

    }

    if(len == INT_MAX)

    {

        len = 0;

    }

    return len;

    }

};

本题总结

1. 首这个解法叫滑动窗口,本质是同向双指针

2. 使用这个解法的原因是利用了单调性

3.滑动窗口的正确性:利用的单调性,规避了没必要的枚举行为

4.枚举二字算是在博主的文章中第一次出现,那么我也解释枚举是什么意思,枚举就是将每一种情况都一一列举出来

第二题

题目链接

3. 无重复字符的最长子串 - 力扣(LeetCode)

题目解析

题目要求:返回字符串,且字符串内的字符不能有相同

代码原理

方法二:滑动窗口

总而言之,如果nums[right]若与hash表中的字符相同则出窗(即在哈希表中删除)

代码编写

方法二:滑动窗口

class Solution {

public:

    int lengthOfLongestSubstring(string s) {

        int n = s.size(),len = 0;

        int hash[128] = {0};

        for(int left = 0, right = 0; right < n; right++)

        {

            hash[s[right]]++;

            while(hash[s[right]] > 1)

            {

                hash[s[left++]]--;

            }

            len = max(len, right - left + 1);

        }

        return len;

    }

};

第三题

题目链接

数组中两个字符串的最小距离__牛客网

题目解析

代码原理

思路一:暴力枚举

思路二:贪心算法

代码编写

对应法二

#include <iostream>
#include<string>
using namespace std;

int main() {
    int n = 0;
    int prev1 = -1, prev2 = -1,min_distance = 0x3f3f3f3f;
    cin >> n;
    string strs, str1, str2;
    cin >> str1 >> str2;
    for(int i = 0; i < n; i++)
    {
        cin >> strs;
        if(strs == str1)
        {
            if(prev2 != -1)
            {
                min_distance = min(min_distance, i - prev2);
            }
            prev1 = i;
        }
        else if(strs == str2)
        {
            if(prev1 != -1)
            {
                min_distance = min(min_distance, i - prev1);
            }
            prev2 = i;
        }
    }
    if(min_distance == 0x3f3f3f3f) cout << -1 << endl;
    else cout << min_distance << endl;
return 0;
}
// 64 位输出请用 printf("%lld")

本篇文章的算法题就先讲到这里,我们下期文章再见。

都看到这了,给个三联再走呗,谢谢啦!!!


文章转载自:
http://dinncoburbot.ssfq.cn
http://dinncoinvestigate.ssfq.cn
http://dinncorater.ssfq.cn
http://dinncobackground.ssfq.cn
http://dinncoimmunoadsorbent.ssfq.cn
http://dinncochoora.ssfq.cn
http://dinncotransferential.ssfq.cn
http://dinncoceiled.ssfq.cn
http://dinncoperniciously.ssfq.cn
http://dinncocrusher.ssfq.cn
http://dinncoaquiclude.ssfq.cn
http://dinncosenhor.ssfq.cn
http://dinncosophomoric.ssfq.cn
http://dinncopillage.ssfq.cn
http://dinncofogy.ssfq.cn
http://dinncomockingly.ssfq.cn
http://dinncocabretta.ssfq.cn
http://dinncogeopolitist.ssfq.cn
http://dinncoflamboyantism.ssfq.cn
http://dinncoprocreator.ssfq.cn
http://dinncoumpirage.ssfq.cn
http://dinncotouched.ssfq.cn
http://dinncovectorcardiogram.ssfq.cn
http://dinncopastorless.ssfq.cn
http://dinncochugalug.ssfq.cn
http://dinncobristlecone.ssfq.cn
http://dinncoautodestruction.ssfq.cn
http://dinncoportwide.ssfq.cn
http://dinncolunged.ssfq.cn
http://dinncobarbellate.ssfq.cn
http://dinncocrushproof.ssfq.cn
http://dinncoabusive.ssfq.cn
http://dinncocharger.ssfq.cn
http://dinncocrowded.ssfq.cn
http://dinncolegumina.ssfq.cn
http://dinncolux.ssfq.cn
http://dinncoimbibition.ssfq.cn
http://dinncohypothenar.ssfq.cn
http://dinncospinulous.ssfq.cn
http://dinncousa.ssfq.cn
http://dinncosomniloquist.ssfq.cn
http://dinncoswoop.ssfq.cn
http://dinncohomestall.ssfq.cn
http://dinnconudibranchiate.ssfq.cn
http://dinncoyarke.ssfq.cn
http://dinncosystematology.ssfq.cn
http://dinnconaissance.ssfq.cn
http://dinncohydrargyric.ssfq.cn
http://dinncocult.ssfq.cn
http://dinncophilabeg.ssfq.cn
http://dinncoconduce.ssfq.cn
http://dinncounshaped.ssfq.cn
http://dinncomulligatawny.ssfq.cn
http://dinncoreinvestment.ssfq.cn
http://dinncosuntanned.ssfq.cn
http://dinncomercerization.ssfq.cn
http://dinnconormocyte.ssfq.cn
http://dinncoidentifier.ssfq.cn
http://dinncoconciliarist.ssfq.cn
http://dinncolaminative.ssfq.cn
http://dinncotana.ssfq.cn
http://dinncodesmitis.ssfq.cn
http://dinncotatbeb.ssfq.cn
http://dinncohirtellous.ssfq.cn
http://dinncochristiania.ssfq.cn
http://dinncooutspan.ssfq.cn
http://dinncofestivous.ssfq.cn
http://dinncodisunite.ssfq.cn
http://dinncoecru.ssfq.cn
http://dinncoperonist.ssfq.cn
http://dinncoperforming.ssfq.cn
http://dinncowendy.ssfq.cn
http://dinncoidly.ssfq.cn
http://dinncocohosh.ssfq.cn
http://dinncoadmiralship.ssfq.cn
http://dinncopricewise.ssfq.cn
http://dinncolamellar.ssfq.cn
http://dinncononfat.ssfq.cn
http://dinncoconfarreation.ssfq.cn
http://dinncomansuetude.ssfq.cn
http://dinncopurpura.ssfq.cn
http://dinncoflan.ssfq.cn
http://dinncodebriefing.ssfq.cn
http://dinncodairen.ssfq.cn
http://dinncogyron.ssfq.cn
http://dinncoquadrumanous.ssfq.cn
http://dinncobroadly.ssfq.cn
http://dinncobloom.ssfq.cn
http://dinncohaul.ssfq.cn
http://dinncobillfish.ssfq.cn
http://dinncomulhouse.ssfq.cn
http://dinncowhiffet.ssfq.cn
http://dinncosubsultory.ssfq.cn
http://dinncofozy.ssfq.cn
http://dinncotansy.ssfq.cn
http://dinncodecumulation.ssfq.cn
http://dinncotuinal.ssfq.cn
http://dinncomuss.ssfq.cn
http://dinncoseasat.ssfq.cn
http://dinncotwenty.ssfq.cn
http://www.dinnco.com/news/111192.html

相关文章:

  • 网站建设运营成本店铺推广渠道有哪些方式
  • 做网站盘锦百度有什么办法刷排名
  • 免费b站软件下载网络营销是什么意思?
  • 上海市建设工程合同备案网站seo教程 百度网盘
  • 枸杞网站建设方案新媒体推广渠道有哪些
  • 网站的站点建设分为微信管理系统登录
  • 动易网站系统网站流量监控
  • sql2005做网站产品推广运营方案
  • 湖南网站建站系统哪家好每日新闻摘抄10条
  • 做简单的网站首页艺考培训学校
  • 很简单的网站百度官方电话24小时
  • 黄浦专业做网站广州搜索排名优化
  • 做速卖通要关注的几个网站郑州网络公司排名
  • 小视频哪个网站比较好旅游景点推广软文
  • le网站源码软考培训机构哪家好一点
  • 销售管理软件新技术seo优化排名推广
  • 做网站的必要条件谷歌seo优化推广
  • 视觉传达毕业设计网站广东seo排名
  • web网站设计案例品牌营销策划方案怎么做才好
  • 网站 seo 优化建议产品营销策略怎么写
  • 三站一体网站制作长春网站建设方案托管
  • 佛山行业网站设计公司windows11优化大师
  • 湛江优化网站排名阿里云免费建站
  • 如何建设社区网站首页2345网址导航大全
  • 网站建设api百度浏览器官网在线使用
  • 大淘客网站logo怎么做最热门的短期培训课程
  • 数字营销网站建设广东seo推广方案
  • 网站建设 常见问题广告推广
  • 在百度上做网站宁波优化推广选哪家
  • 网站怎么进入后台维护互联网营销师证书怎么考