2024每日刷题(161)
Leetcode—1184. 公交站间的距离
实现代码
class Solution {
public:int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {int clockwise = 0;int counterclockwise = 0;if(start > destination) {swap(start, destination);}int n = distance.size();for(int i = 0; i < n; i++) {if(i >= start && i < destination) {clockwise += distance[i];} else {counterclockwise += distance[i];}}return min(clockwise, counterclockwise);}
};
运行结果
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!