当前位置:网站首页>1184. 公交站间的距离
1184. 公交站间的距离
2022-07-24 16:23:00 【anieoo】
原题链接:1184. 公交站间的距离
solution:
class Solution {
public:
int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {
int ans1 = 0, asn2 = 0; //保存正向和反向的距离
int n = distance.size();
for(int i = start;i != destination;i = (i + 1) % n) ans1 += distance[i]; //正向距离
for(int i = destination;i != start;i = (i + 1) % n) asn2 += distance[i]; //逆向距离
return min(ans1, asn2);
}
};边栏推荐
- VSCode如何鼠标滚轮放大界面
- Rest style
- 31 next spread
- Codeforces round 690 (Div. 3) C. unique number conventional solution
- 2022/7/18 CF training
- 15、ARM嵌入式系统:如何用PC调试单板
- Knowledge points of MySQL (12)
- 【LOJ3247】「USACO 2020.1 Platinum」Non-Decreasing Subsequences(DP,分治)
- Replace the image source of Debian full version with Alibaba cloud image source
- There are more than 20 categories of the four operators in MySQL. It took three days and three nights to sort them out. Don't collect them quickly
猜你喜欢

矩阵的秩和图像的秩的一些了解

简单使用 MySQL 索引

多线程(基础)

Some understanding of the rank sum of matrix and the rank of image

Will the capital market be optimistic about TCL's folding screen story?

Multithreading (basic)

About SQL data query statements

C# TCP客户端窗体应用程序异步接收方式

124 maximum path sum in binary tree

Power of leetcode 231.2
随机推荐
Image label processing -- converting JSON files into PNG files
解决Eureka默认缓存配置导致时效性问题
Cache penetration, cache breakdown, cache avalanche differences and solutions [easy to understand]
Software - prerequisite software
Knowledge points of MySQL (12)
简单工厂模式都不会,你真应该去工厂搬砖!
狗牙根植物介绍
22 bracket generation
REST风格
Custom view - Custom button
Codeforces round 690 (Div. 3) B. last year's substring conventional solution
Solution to deepin taskbar disappearance
VSCode如何鼠标滚轮放大界面
Servlet框架(servlet+jsp)+Mysql实现的增删改查+分页(功能包学生信息录入、学生信息增删改查、分页等)
Code shoe set - mt2095 · zigzag jump
Introduction to bermudagrass
Array in PHP_ The pit of merge
"Heaven and the world, self-respect" -- single case mode
Stack and queue - 1047. Delete all adjacent duplicates in the string
Programming in CoDeSys to realize serial communication [based on raspberry pie 4B]