当前位置:网站首页>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

边栏推荐
- php中可以使用取绝对值函数 abs() 将负数转成正数
- Wechat applet to realize music player (4) (use pubsubjs to realize inter page communication)
- 规则引擎Drools的使用
- JS Base64 encoding and decoding
- 【第019问 Unity中对SpherecastCommand的理解?】
- 5年1.4W倍,NFT OG 的封神之路|Web3专栏
- 加班一周开发了报表系统,这个低代码免费IT报表神器太好用了
- Trust sums two numbers
- [in depth study of 4g/5g/6g topic-42]: urllc-13 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -7-low delay technology-1-subcarrier spacing expansio
- Small ball and box model, arrangement and combination
猜你喜欢

If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing

Dracoo Master天龙卡牌大师

Find my technology | the Internet of things asset tracking market has reached US $6.6 billion, and find my helps the market develop

1311_ Hardware design_ Summary of ICT concept, application, advantages and disadvantages
![Acwing game 61 [End]](/img/e3/191f7d888fc8cced608d41ef837a92.png)
Acwing game 61 [End]

(翻译)按钮位置约定能强化用户使用习惯

如何构建面向海量数据、高实时要求的企业级OLAP数据引擎?

触觉智能分享-RK3568在景区导览机器人中的应用

安装VMware报错failed to install the hcmon driver

微信小程序实现音乐播放器(4)(使用pubsubjs实现页面间通信)
随机推荐
Uniapp pit filling Tour
Opencv learning notes -- Hough transform
智装时代已来,智哪儿邀您一同羊城论剑,8月4日,光亚展恭候
Kbpc1510-asemi large chip 15A rectifier bridge kbpc1510
General test case writing specification
座椅/安全配置升级 新款沃尔沃S90行政体验到位了吗
资深报表开发经验总结:明白这一点,没有做不好的报表
深度学习之DAT
Seat / safety configuration upgrade is the administrative experience of the new Volvo S90 in place
测试用例设计方法之——招式组合,因果判定
Brief tutorial for soft exam system architecture designer | case analysis and problem solving skills
通用测试用例写作规范
Worked overtime for a week to develop a reporting system. This low code free it reporting artifact is very easy to use
PHP object conversion array
【数字IC/FPGA】热独码检测
PHP < => spacecraft operator (combined comparator)
php 实现从1累加到100的算法
Sentinel fusing and current limiting
1311_ Hardware design_ Summary of ICT concept, application, advantages and disadvantages
Chapter 18: explore the wonders of the mean in the 2-bit a~b system, specify the 3x+1 conversion process of integers, specify an interval to verify the angular Valley conjecture, explore the number of