1 Star 0 Fork 0

SatelliteR63/LeetCode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
2100.cpp 1.28 KB
一键复制 编辑 原始数据 按行查看 历史
SatelliteR63 提交于 2022-03-09 19:41 +08:00 . 3.9
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Solution
{
public:
vector<int> goodDaysToRobBank(vector<int> &security, int time)
{
vector<int> ans{};
vector<int> left(security.size(), 0);
vector<int> right(security.size(), 0);
if (time == 0)
{
for (int i = 0; i < security.size(); i++)
ans.push_back(i);
return ans;
}
if (security.size() < time * 2 + 1)
return ans;
int t = 0, index = 0;
for (int i = 1; i < security.size(); i++)
{
if (security[i - 1] >= security[i])
left[i] = left[i - 1] + 1;
}
for (int i = security.size() - 2; i >= 0; i--)
{
if (security[i] <= security[i + 1])
right[i] = right[i + 1] + 1;
}
for (int i = 0; i < security.size(); i++)
{
if (left[i] >= time && right[i] >= time)
ans.push_back(i);
}
return ans;
}
};
int main()
{
Solution *s = new Solution();
vector<int> ans;
vector<int> security{5, 3, 3, 3, 5, 6, 2};
ans = s->goodDaysToRobBank(security, 2);
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/satelliter63/leet-code.git
git@gitee.com:satelliter63/leet-code.git
satelliter63
leet-code
LeetCode
master

搜索帮助