当前位置:网站首页>Leetcode:1184. Distance between bus stops -- simple
Leetcode:1184. Distance between bus stops -- simple
2022-07-26 04:05:00 【Kinght_ one hundred and twenty-three】

Catalog
subject
1184. The distance between bus stops
There are... On the circular bus route n Individual station , From 0 To n - 1 Number . We know the distance between each pair of adjacent bus stops ,distance[i] Indicates that the number is i The station and number are (i + 1) % n The distance between the stations .
The buses on the loop line can travel clockwise and counterclockwise .
Return passengers from the starting point start Destination destination The shortest distance between .
Example 1:
Input :distance = [1,2,3,4], start = 0, destination = 1
Output :1
explain : Bus stop 0 and 1 The distance between them is 1 or 9, The minimum is 1.
Example 2:
Input :distance = [1,2,3,4], start = 0, destination = 2
Output :3
explain : Bus stop 0 and 2 The distance between them is 3 or 7, The minimum is 3.
Example 3:
Input :distance = [1,2,3,4], start = 0, destination = 3
Output :4
explain : Bus stop 0 and 3 The distance between them is 6 or 4, The minimum is 4.
Tips :
- 1 <= n <= 10^4
- distance.length == n
- 0 <= start, destination < n
- 0 <= distance[i] <= 10^4
Their thinking
- Just traverse once .
Code
class Solution:
def distanceBetweenBusStops(self, distance: List[int], start: int, destination: int) -> int:
if start > destination:
start = start ^ destination
destination = start ^ destination
start = start ^ destination
return min(sum(distance[start:destination]), sum(distance[:start]) + sum(distance[destination:]))
Running results

边栏推荐
- 【读书笔记->数据分析】BDA教材《数据分析》书籍介绍
- [Reading Notes - > data analysis] Introduction to BDA textbook data analysis
- 2022 Hangzhou Electric Multi school bowcraft
- Apple removed the last Intel chip from its products
- 在 Istio 服务网格内连接外部 MySQL 数据库
- [cloud native kubernetes] how to use configmap under kubernetes cluster
- laravel8 实现接口鉴权封装使用JWT
- Implementation of distributed lock
- Find my technology | the Internet of things asset tracking market has reached US $6.6 billion, and find my helps the market develop
- Course selection information management system based on SSM
猜你喜欢

1311_ Hardware design_ Summary of ICT concept, application, advantages and disadvantages

Failed to install the hcmon driver

booking.com缤客上海面经

Inventory the concept, classification and characteristics of cloud computing

MySQL索引失效场景以及解决方案
![Matrix and Gauss elimination [matrix multiplication, Gauss elimination, solving linear equations, solving determinants] the most detailed in the whole network, with examples and sister chapters of 130](/img/84/e5cb5199fe4602440b50dfc4afe963.gif)
Matrix and Gauss elimination [matrix multiplication, Gauss elimination, solving linear equations, solving determinants] the most detailed in the whole network, with examples and sister chapters of 130

Opencv learning notes -- Hough transform

Apple removed the last Intel chip from its products
![Acwing game 61 [End]](/img/e3/191f7d888fc8cced608d41ef837a92.png)
Acwing game 61 [End]

2021 CIKM |GF-VAE: A Flow-based Variational Autoencoder for Molecule Generation
随机推荐
JS get some attributes of the object
[programmers must] Tanabata confession strategy: "the moon meets the cloud, the flowers meet the wind, and the night sky is beautiful at night". (with source code Collection)
Maximum average value of continuous interval
Where does international crude oil open an account, a formal, safe and secure platform
How to use graffiti magic color product development kit
Worked overtime for a week to develop a reporting system. This low code free it reporting artifact is very easy to use
【数字IC/FPGA】热独码检测
触觉智能分享-RK3568在景区导览机器人中的应用
Small ball and box model, arrangement and combination
Realization of online shopping mall system based on JSP
电商运营小白,如何快速入门学习数据分析?
Course selection information management system based on SSM
Chinese database oceanbase was selected into the Forrester translational data platform report
(翻译)网站流程图和用户流程图的使用时机
涂鸦幻彩产品开发包如何使用
php中可以使用取绝对值函数 abs() 将负数转成正数
【二叉树】二叉树中的最长交错路径
【第019问 Unity中对SpherecastCommand的理解?】
PHP save array to var file_ export、serialize
Implementation of distributed lock