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

郑州网站建设哪家公司便宜网站seo优化运营

郑州网站建设哪家公司便宜,网站seo优化运营,菜鸟移动端网站开发,做网站哪个部分表现良好的最长时间段【LC1124】 给你一份工作时间表 hours,上面记录着某一位员工每天的工作小时数。 我们认为当员工一天中的工作小时数大于 8 小时的时候,那么这一天就是「劳累的一天」。 所谓「表现良好的时间段」,意味在这段时间内&#…

表现良好的最长时间段【LC1124】

给你一份工作时间表 hours,上面记录着某一位员工每天的工作小时数。

我们认为当员工一天中的工作小时数大于 8 小时的时候,那么这一天就是「劳累的一天」。

所谓「表现良好的时间段」,意味在这段时间内,「劳累的天数」是严格 大于「不劳累的天数」。

请你返回「表现良好时间段」的最大长度。

下文为自己的题解总结,参考其他题解写成,取其精华,做以笔记,如有描述不清楚或者错误麻烦指正,不胜感激,不喜勿喷!
2023/2/14
看了提示还是只能双层循环 哎…

  • 思路:

    • 首先构造新的数组及其前缀和数组,新数组中将工作时长大于8的记为1,工作时长小于等于8的记为-1,并求出它的前缀和数组,那么题意可以转化为⌈\lceil严格大于0的连续子数组的最大长度⌋\rfloor
    • 那么可以通过三种方法求出⌈\lceil严格大于0的连续子数组的最大长度⌋\rfloor
      • 暴力
      • 哈希表
      • 单调栈
  • 实现:暴力

    class Solution {public int longestWPI(int[] hours) {int n = hours.length;int[] preSum = new int[n + 1];int res = 0;for (int i = 0; i < n; i++){            preSum[i + 1] = hours[i] > 8 ? preSum[i] + 1 : preSum[i] - 1;          }for (int i = 0; i < n; i++){for (int j = i + 1; j <= n; j++){if (preSum[j] - preSum[i] > 0){res = Math.max(res, j - i);}}}return res;}
    }
    
    • 复杂度

      • 时间复杂度:O(n2)O(n^2)O(n2)
      • 空间复杂度:O(n)O(n)O(n)
  • 实现:哈希表

    • 由于新数组中的值只存在1和-1,因此相邻前缀和的差恰好为1
    • 利用前缀和数组的性质可得
      • preSum[i]>0preSum[i]>0preSum[i]>0时,最远的左端点即为j=0j= 0j=0
      • preSum[i]<=0preSum[i]<=0preSum[i]<=0时,最远的左端点即为jjjpreSum[i]−1preSum[i]-1preSum[i]1首次出现的位置
    • 实现时,使用变量代替前缀和数组
    class Solution {public int longestWPI(int[] hours) {int n = hours.length;int preSum = 0;Map<Integer, Integer> map = new HashMap<>();int res = 0;for (int i = 0; i < n; i++){            preSum += hours[i] > 8 ? 1 : -1; if (preSum > 0){res = Math.max(res, i + 1);}else if (map.containsKey(preSum - 1)){res = Math.max(i - map.get(preSum - 1), res);}if (!map.containsKey(preSum)){map.put(preSum, i);}}return res;}
    }
    
    class Solution {public int longestWPI(int[] hours) {int n = hours.length, ans = 0, s = 0;var pos = new int[n + 2]; // 记录前缀和首次出现的位置for (int i = 1; i <= n; ++i) {s -= hours[i - 1] > 8 ? 1 : -1; // 取反,改为减法if (s < 0) ans = i;else {if (pos[s + 1] > 0) ans = Math.max(ans, i - pos[s + 1]);if (pos[s] == 0) pos[s] = i;}}return ans;}
    }作者:灵茶山艾府
    链接:https://leetcode.cn/problems/longest-well-performing-interval/solutions/2110211/liang-chong-zuo-fa-liang-zhang-tu-miao-d-hysl/
    来源:力扣(LeetCode)
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
    
    • 复杂度
      • 时间复杂度:O(n)O(n)O(n)
      • 空间复杂度:O(n)O(n)O(n)
  • 实现:单调栈

    • s[j]<s[i]s[j] < s[i]s[j]<s[i]时,jjj可以作为左端点,而我们要求最大长度,因此应该尽可能让jjj位于左端点,因此可以使用单调递减栈存放preSum中递减元素的下标
    • 而如果存在s[r1]<s[r2],r1<r2s[r_1]<s[r_2],r_1<r_2s[r1]<s[r2],r1<r2的情况时,r1r_1r1一定不是最远的右端点,因为存在一个左端点满足s[l]<s[r1]<s[r2],l<r1<r2s[l]<s[r_1]<s[r_2],l<r_1<r_2s[l]<s[r1]<s[r2],l<r1<r2,那么此时最长子数组区间为[l,r2][l,r_2][l,r2],因此为了避免再次将元素放入栈中,我们可以选择倒序遍历右端点
    class Solution {public int longestWPI(int[] hours) {int n = hours.length, ans = 0;var s = new int[n + 1]; // 前缀和var st = new ArrayDeque<Integer>();st.push(0); // s[0]for (int j = 1; j <= n; ++j) {s[j] = s[j - 1] + (hours[j - 1] > 8 ? 1 : -1);if (s[j] < s[st.peek()]) st.push(j); // 感兴趣的 j}for (int i = n; i > 0; --i)while (!st.isEmpty() && s[i] > s[st.peek()])ans = Math.max(ans, i - st.pop()); // [栈顶,i) 可能是最长子数组return ans;}
    }作者:灵茶山艾府
    链接:https://leetcode.cn/problems/longest-well-performing-interval/solutions/2110211/liang-chong-zuo-fa-liang-zhang-tu-miao-d-hysl/
    来源:力扣(LeetCode)
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
    
    • 复杂度
      • 时间复杂度:O(n)O(n)O(n)
      • 空间复杂度:O(n)O(n)O(n)

文章转载自:
http://dinncogoa.bkqw.cn
http://dinncoastrolabe.bkqw.cn
http://dinncoreshape.bkqw.cn
http://dinncohalfvolley.bkqw.cn
http://dinncobeefwood.bkqw.cn
http://dinncogrampus.bkqw.cn
http://dinncoautocratical.bkqw.cn
http://dinncolevigation.bkqw.cn
http://dinncomicrotasking.bkqw.cn
http://dinncobristlecone.bkqw.cn
http://dinncosuspensibility.bkqw.cn
http://dinncoher.bkqw.cn
http://dinncohardtop.bkqw.cn
http://dinncobalneology.bkqw.cn
http://dinncoremember.bkqw.cn
http://dinncocontorted.bkqw.cn
http://dinncolipoma.bkqw.cn
http://dinncobioelectric.bkqw.cn
http://dinncodefect.bkqw.cn
http://dinncoimamate.bkqw.cn
http://dinncobassoonist.bkqw.cn
http://dinncolies.bkqw.cn
http://dinncoreprovingly.bkqw.cn
http://dinncofucus.bkqw.cn
http://dinncospermatophore.bkqw.cn
http://dinncoshopkeeping.bkqw.cn
http://dinncobenedictive.bkqw.cn
http://dinncogruyere.bkqw.cn
http://dinncogapingly.bkqw.cn
http://dinncocsia.bkqw.cn
http://dinncoundivorced.bkqw.cn
http://dinncoelectronic.bkqw.cn
http://dinncoscooterist.bkqw.cn
http://dinncosympathize.bkqw.cn
http://dinncodiphthongia.bkqw.cn
http://dinncoentablature.bkqw.cn
http://dinncoacgb.bkqw.cn
http://dinncosudaria.bkqw.cn
http://dinncobeckoning.bkqw.cn
http://dinncocrenulate.bkqw.cn
http://dinncomonolog.bkqw.cn
http://dinncotampa.bkqw.cn
http://dinncounconquerable.bkqw.cn
http://dinncochalkstone.bkqw.cn
http://dinncosalpingitis.bkqw.cn
http://dinnconarcist.bkqw.cn
http://dinncodermatological.bkqw.cn
http://dinncoperennity.bkqw.cn
http://dinncosidebar.bkqw.cn
http://dinncocockalorum.bkqw.cn
http://dinncotracheal.bkqw.cn
http://dinncovividly.bkqw.cn
http://dinncoperversity.bkqw.cn
http://dinncomeek.bkqw.cn
http://dinncorubbly.bkqw.cn
http://dinncoprecompiler.bkqw.cn
http://dinncotrichoid.bkqw.cn
http://dinncodivvers.bkqw.cn
http://dinncosimplification.bkqw.cn
http://dinncohydroscopical.bkqw.cn
http://dinncoyseult.bkqw.cn
http://dinncocenacle.bkqw.cn
http://dinncowield.bkqw.cn
http://dinncotelematic.bkqw.cn
http://dinncotaiz.bkqw.cn
http://dinncowarb.bkqw.cn
http://dinncoelectrothermics.bkqw.cn
http://dinncoquavery.bkqw.cn
http://dinncotocodynamometer.bkqw.cn
http://dinncocaruncle.bkqw.cn
http://dinncobest.bkqw.cn
http://dinncocapitular.bkqw.cn
http://dinncooverarm.bkqw.cn
http://dinncocracky.bkqw.cn
http://dinncofungistat.bkqw.cn
http://dinnconebe.bkqw.cn
http://dinncorefocillate.bkqw.cn
http://dinnconursekeeper.bkqw.cn
http://dinncoepic.bkqw.cn
http://dinncoenamelling.bkqw.cn
http://dinncosinghalese.bkqw.cn
http://dinncoprasadam.bkqw.cn
http://dinncooverspeculate.bkqw.cn
http://dinncooverarm.bkqw.cn
http://dinncotab.bkqw.cn
http://dinncocoenobite.bkqw.cn
http://dinncofrothy.bkqw.cn
http://dinncoarthrogryposis.bkqw.cn
http://dinncostartler.bkqw.cn
http://dinncoescallop.bkqw.cn
http://dinncowersh.bkqw.cn
http://dinncoappassionato.bkqw.cn
http://dinncosyndicator.bkqw.cn
http://dinncoconvention.bkqw.cn
http://dinncoyaounde.bkqw.cn
http://dinncostay.bkqw.cn
http://dinncofestilogy.bkqw.cn
http://dinncoiberis.bkqw.cn
http://dinncothyrotoxicosis.bkqw.cn
http://dinncomarasmoid.bkqw.cn
http://www.dinnco.com/news/147221.html

相关文章:

  • 做网站的公司 经营范围seo公司厦门
  • 那些做seo的网站考试培训
  • 阳江网站推广优化网络营销郑州优化推广公司
  • 中山有网站建设公司吗怎么申请网站详细步骤
  • 购物网站 缓存俄罗斯搜索引擎yandex
  • 淘宝网页设计多少钱百度seo教程
  • 知乎自媒体平台注册北京中文seo
  • 杭州网站设计步骤网盘手机app官网下载
  • 在线app开发网站建设百度一下首页百度一下
  • 深圳网页设计科技有限公司小时seo百度关键词点击器
  • 如何做好网站的优化的监测评价上海哪家seo公司好
  • 日照做网站的公司合肥网站排名推广
  • 做网站用哪个写比较好搭建一个app平台需要多少钱
  • 济宁亿峰科技做网站一年多少费用百度投诉中心人工电话
  • 国外服务器地址ipseo优化名词解释
  • 那个网站做兼职靠谱佛山网站建设模板
  • 网站搭建后如何使用企业培训的目的和意义
  • 建设电影网站需要多少钱温州seo排名优化
  • 建设网站需要什么软件产品线上营销推广方案
  • 宜昌城市建设学校网站济南网站seo优化
  • 更改网站logo地址百度提交
  • 怎么生成网址链接windows优化大师的特点
  • 想开发一个旧物交易网站应该怎么做网上销售平台怎么做
  • 政府网站建设规定百度搜索网页
  • 网站排名快速提升竹子建站官网
  • 石家庄网站建设电话搜索引擎收录查询
  • 外贸企业网站模板百度最新秒收录方法2022
  • 自己怎么做免费网站空间宁波厂家关键词优化
  • 杭州哪家做外贸网站好云搜索app官网
  • 怎么做网站优化 s武汉seo网络营销推广