2 Star 0 Fork 0

xinanXu/myleetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
LC1184.cpp 539 Bytes
一键复制 编辑 原始数据 按行查看 历史
xinanXu 提交于 2023-02-14 00:32 . 1184 公交站间的距离
class Solution {
public:
int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {
if (start > destination) swap(start, destination);
int Max1 = 0, Max2 = 0;
int len = distance.size();
for (int i = 0; i < start; i++)
Max2 += distance[i];
for (int i = start; i < destination; i++)
Max1 += distance[i];
for (int i = destination; i < len; i++)
Max2 += distance[i];
return Max1 < Max2 ? Max1 : Max2;
}
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/DearAtri/myleetcode.git
git@gitee.com:DearAtri/myleetcode.git
DearAtri
myleetcode
myleetcode
master

搜索帮助