1 Star 0 Fork 0

杨杰 / 力扣第2672题

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
力扣第2672题.txt 921 Bytes
一键复制 编辑 原始数据 按行查看 历史
杨杰 提交于 2023-05-09 19:48 . 力扣第2672题.txt
class Solution {
public:
vector<int> colorTheArray(int n, vector<vector<int>>& queries) {
int ans=0;
int m=queries.size();
vector<int> ret;
vector<int> arr(n,0);
for(int i=0;i<m;i++)
{
int x=queries[i][0];
int y=queries[i][1];
if(arr[x]==0)
{
if(x-1>=0&&arr[x-1]==y)
++ans;
if(x+1<n&&arr[x+1]==y)
++ans;
}
else
{
int count=0;
if(x-1>=0&&arr[x-1]==arr[x])
--ans;
if(x+1<n&&arr[x]==arr[x+1])
--ans;
if(x-1>=0&&arr[x-1]==y)
++ans;
if(x+1<n&&arr[x+1]==y)
++ans;
}
arr[x]=y;
ret.push_back(ans);
}
return ret;
}
};
C++
1
https://gitee.com/yang-jieCyuyan/deduction-of-question-2672.git
git@gitee.com:yang-jieCyuyan/deduction-of-question-2672.git
yang-jieCyuyan
deduction-of-question-2672
力扣第2672题
master

搜索帮助