## 水果成篮-力扣

``````class Solution {
public:int totalFruit(vector<int>& fruits) {int slowindex = 0;int fastindex = 1;int sum= 1;int kind = 1;int key1 = fruits[slowindex];int key2 = -1;if(fruits.size() == 0){return 0;}while(fastindex < fruits.size()){if(kind < 2){if(fruits[fastindex] == key1){fastindex++;sum++;}else if(key2 < 0){key2 = fruits[fastindex];kind++;sum++;fastindex++;}}if(fruits[fastindex] == key1 || fruits[fastindex] == key2){sum++;fastindex++;}else{kind++;}while(kind >= 3){slowindex = fastindex - 1;key1 = fruits[slowindex--];while(fruits[slowindex] == key1){slowindex--;}key2 = fruits[fastindex];kind--;fastindex++;}sum = max(sum, fastindex - slowindex - 1);}return sum;}
};
``````

• sum的更新和维护，在代码1中，没有用到currentsum来记录当前的最大值，仅仅使用了一个sum来计数，导致这个sum在满足条件 fruits[fastindex] == key1 || fruits[fastindex] == key2 时便会增加，从而导致sum不断增加，fastindex - slowindex - 1 不会被取到。修改后的代码如下：
``````class Solution {
public:int totalFruit(vector<int>& fruits) {int slowindex = 0;int fastindex = 0;int sum = 0;int currentsum = 0;int key1 = fruits[slowindex];int key2 = -1;while(fastindex < fruits.size()) {if (fruits[fastindex] == key1 || fruits[fastindex] == key2) {currentsum++;fastindex++;} else{if (key2 == -1) {key2 = fruits[fastindex];currentsum++;fastindex++;}else{sum = max(sum, currentsum);currentsum = 2;slowindex = fastindex - 1;key1 = fruits[slowindex];while (slowindex > 0 && fruits[slowindex - 1] == key1) {currentsum++;slowindex--;}key2 = fruits[fastindex];fastindex++;}}}sum = max(sum, currentsum);return sum;}
};
``````

### Ubuntu24.04安装tabby-terminal-1.0.207并处理依赖

1 下载 tabby-terminal-1.0.207 地址&#xff1a; https://github.com/Eugeny/tabby/releases 点击show all 36 assets 选择 tabby-1.0.207-linux-x64.deb 并下载。 2 依赖下载 gconf2_3.2.6-3ubuntu6_amd64.deb gconf2-common_3.2.6-3ubuntu6_all.deb gconf-service_3.2.6-…

### 【Matlab函数分析】绘图函数：colormap查看并设置当前颜色图

&#x1f517; 运行环境&#xff1a;Matlab &#x1f6a9; 撰写作者&#xff1a;左手の明天 &#x1f947; 精选专栏&#xff1a;《python》 &#x1f525; 推荐专栏&#xff1a;《算法研究》 #### 防伪水印——左手の明天 #### &#x1f497; 大家好&#x1f917;&#x1f91…

### Elasticsearch之入门与安装

Elaticsearch&#xff0c;简称为es&#xff0c; es是一个开源的高扩展的分布式全文检索引擎&#xff0c;它可以近乎实时的存储、检索数据&#xff1b;本身扩展性很好&#xff0c;可以扩展到上百台服务器&#xff0c;处理PB级别的数据。es也使用Java开发并使用Lucene作为其核心来…

### Activiti7_使用

Activiti7_使用 一、Activiti7二、绘制工作流三、通过代码部署流程&#xff0c;再对流程进行实例化&#xff0c;完整运行一遍流程即可四、在springbooot中使用 一、Activiti7 为了实现后端的咨询流转功能&#xff0c;学习Activiti7&#xff0c;记录下使用的过程及遇到的问题 二…

### 常见算法（1）

1.基本查找/顺序查找 核心&#xff1a;从0索引之后挨个查找 实现代码&#xff1a; public class test {public static void main(String [] arg) throws ParseException {int[] arr {121,85,46,15,55,77,63,49};int number55;System.out.println(bashi(arr,number));}publi…

### React18 apexcharts数据可视化之甜甜圈图

03 甜甜圈图 apexcharts数据可视化之甜甜圈图。 有完整配套的Python后端代码。 本教程主要会介绍如下图形绘制方式&#xff1a; 基本甜甜圈图个性图案的甜甜圈图渐变色的甜甜圈图 面包圈 import ApexChart from react-apexcharts;export function DonutUpdate() {// 数据…