当前位置:网站首页>1184. Distance between bus stops
1184. Distance between bus stops
2022-07-24 16:27:00 【anieoo】
Original link :1184. The distance between bus stops
solution:
class Solution {
public:
int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {
int ans1 = 0, asn2 = 0; // Save the forward and reverse distances
int n = distance.size();
for(int i = start;i != destination;i = (i + 1) % n) ans1 += distance[i]; // Positive distance
for(int i = destination;i != start;i = (i + 1) % n) asn2 += distance[i]; // Reverse distance
return min(ans1, asn2);
}
};边栏推荐
- Getting started with ARP
- Simply use MySQL index
- Parse string
- Servlet框架(servlet+jsp)+Mysql实现的增删改查+分页(功能包学生信息录入、学生信息增删改查、分页等)
- [leetcode] day103 search two-dimensional matrix II
- 【技术】uniapp 之 在线选座 demo
- Creation and inheritance of JS class
- Princeton calculus reader 02 Chapter 1 -- composition of functions, odd and even functions, function images
- 做完数据治理,质量依旧很差
- 【LeetCode】Day102-螺旋矩阵 II
猜你喜欢

Getting started with ARP

Yolov4 trains its own data set

C TCP client form application asynchronous receiving mode

After data management, the quality is still poor

Yolov3 trains its own data set

Caikeng Alibaba cloud Kex_ exchange_ identification: read: Connection reset by peer

15. ARM embedded system: how to debug single board with PC

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

How vscode mouse wheel enlarges the interface

ArcGIS layer annotation display
随机推荐
How vscode mouse wheel enlarges the interface
[Nanjing Agricultural University] information sharing of postgraduate entrance examination and re examination
"Heaven and the world, self-respect" -- single case mode
Envi5.3 open GF-1 WFV data
Use of ec200u-cn module
简单使用 MySQL 索引
ZBar source code analysis - img_ scanner. c | [email protected]
[leetcode] day102 spiral matrix II
Some understanding of the rank sum of matrix and the rank of image
Software - prerequisite software
Can flush accounts be opened directly? Is it safe to open an account? How to open an account??
简易版QQ?Qt也可以实现!(一)
hping3安装使用
Picture browser? QT can also be achieved!
Jenkins CLI 命令详解
Parse string
JUC源码学习笔记3——AQS等待队列和CyclicBarrier,BlockingQueue
If this.$router Push the same address with different parameters, and the page does not refresh
Princeton calculus reader 02 Chapter 1 -- composition of functions, odd and even functions, function images
ZBar project introduction and installation configuration| [email protected]