golang力扣leetcode 2024.考试的最大困扰度

简介: golang力扣leetcode 2024.考试的最大困扰度

2024.考试的最大困扰度

2024.考试的最大困扰度

题解

滑动窗口模板题

代码

package main
//右指针右移之后窗口数据更新
//判断窗口是否要收缩
//左指针右移之后窗口数据更新
//根据题意计算结果
func maxConsecutiveAnswers(answerKey string, k int) int {
  return max(window(answerKey, k, 'T'), window(answerKey, k, 'F'))
}
func window(s string, k int, ch uint8) (ans int) {
  left := 0
  sum := 0
  for right := range s {
    if s[right] != ch {
      sum++
    }
    for sum > k {
      if s[left] == ch {
        sum--
      }
      left++
    }
    ans = max(ans, right-left+1)
  }
  return
}
func max(i, j int) int {
  if i > j {
    return i
  }
  return j
}
目录
相关文章
|
4天前
|
Java
【LeetCode力扣】面试题 17.14. 最小K个数(top-k问题)
【LeetCode力扣】面试题 17.14. 最小K个数(top-k问题)
12 1
|
4天前
|
存储 算法
【LeetCode力扣】单调栈解决Next Greater Number(下一个更大值)问题
【LeetCode力扣】单调栈解决Next Greater Number(下一个更大值)问题
6 0
|
4天前
|
Go 容器 SQL
【Golang Leetcode】总目录(Day1~100)
【Golang Leetcode】总目录(Day1~100)
477 1
【Golang Leetcode】总目录(Day1~100)
|
4天前
|
Go
golang力扣leetcode 494.目标和
golang力扣leetcode 494.目标和
32 0
|
4天前
|
Go
golang力扣leetcode 剑指Offer II 114. 外星文字典
golang力扣leetcode 剑指Offer II 114. 外星文字典
21 0
|
4天前
|
算法 C++
【刷题】Leetcode 1609.奇偶树
这道题是我目前做过最难的题,虽然没有一遍做出来,但是参考大佬的代码,慢慢啃的感觉的真的很好。刷题继续!!!!!!
9 0
|
4天前
|
算法 索引
【刷题】滑动窗口精通 — Leetcode 30. 串联所有单词的子串 | Leetcode 76. 最小覆盖子串
经过这两道题目的书写,相信大家一定深刻认识到了滑动窗口的使用方法!!! 下面请大家继续刷题吧!!!
12 0
|
4天前
|
算法
【刷题】 leetcode 面试题 08.05.递归乘法
递归算法是一种在计算机科学和数学中广泛应用的解决问题的方法,其基本思想是利用问题的自我相似性,即将一个大问题分解为一个或多个相同或相似的小问题来解决。递归算法的核心在于函数(或过程)能够直接或间接地调用自身来求解问题的不同部分,直到达到基本情况(也称为基础案例或终止条件),这时可以直接得出答案而不必再进行递归调用。
25 4
【刷题】 leetcode 面试题 08.05.递归乘法
|
4天前
|
存储 算法 安全
【刷题】 leetcode 面试题 01.06 字符串压缩
来看效果: 非常好!!!过啦!!!
25 5
【刷题】 leetcode 面试题 01.06 字符串压缩