当前位置:网站首页>2022.07.24_Daily Question
2022.07.24_Daily Question
2022-07-31 07:40:00 【No. い】
1184. 公交站间的距离
题目描述
环形公交路线上有 n 个站,按次序从 0 到 n - 1 进行编号.我们已知每一对相邻公交站之间的距离,distance[i] 表示编号为 i 的车站和编号为 (i + 1) % n 的车站之间的距离.
环线上的公交车都可以按顺时针和逆时针的方向行驶.
返回乘客从出发点 start 到目的地 destination 之间的最短距离.
示例 1:

输入:distance = [1,2,3,4], start = 0, destination = 1 输出:1 解释:公交站 0 和 1 之间的距离是 1 或 9,最小值是 1.
示例 2:

输入:distance = [1,2,3,4], start = 0, destination = 2 输出:3 解释:公交站 0 和 2 之间的距离是 3 或 7,最小值是 3.
示例 3:

输入:distance = [1,2,3,4], start = 0, destination = 3 输出:4 解释:公交站 0 和 3 之间的距离是 6 或 4,最小值是 4.
提示:
1 <= n <= 10^4distance.length == n0 <= start, destination < n0 <= distance[i] <= 10^4
- 数组
coding
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
public int distanceBetweenBusStops(int[] distance, int start, int destination) {
int len = distance.length;
int len1 = 0;
int len2 = 0;
if (start > destination) {
start = start ^ destination;
destination = start ^ destination;
start = start ^ destination;
}
for (int i = start; i < destination; i++) {
len1 += distance[i];
}
for (int i = destination; i < len + start; i++) {
len2 += distance[i % len];
}
return Math.min(len1, len2);
}
}
//leetcode submit region end(Prohibit modification and deletion)
边栏推荐
- Exam Questions Previous True Questions Wrong Bills [The Fourth Session] [Provincial Competition] [Group B]
- 2022.07.12_每日一题
- Chapter 16: Constructing the Magic Square for Prime Numbers of Order n(5,7)
- Postgresql source code learning (34) - transaction log ⑩ - full page write mechanism
- 芯塔电子斩获第十一届中国双创大赛芜湖赛区桂冠
- 【Star项目】小帽飞机大战(八)
- 庐山谣寄卢侍御虚舟
- Web浏览器工作流程解析
- Zotero | Zotero translator plugin update | Solve the problem that Baidu academic literature cannot be obtained
- Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
猜你喜欢

shell之条件语句(test、if、case)

Analysis of the implementation principle and detailed knowledge of v-model syntactic sugar and how to make the components you develop support v-model

Yu Mr Series 】 【 2022 July 022 - Go Go teaching course of container in the dictionary

简单谈谈Feign

LeetCode brush # 376 # Medium - swing sequence

Financial leasing business

Leetcode952. 按公因数计算最大组件大小

【网络攻防】常见的网络攻防技术——黑客攻防(通俗易懂版)

【微服务】 微服务学习笔记二:Eureka注册中心的介绍及搭建

03-SDRAM: Write operation (burst)
随机推荐
SCI写作指南
Chapter 17: go back to find the entrance to the specified traverse, "ma bu" or horse stance just look greedy, no back to search traversal, "ma bu" or horse stance just look recursive search NXM board
Log4net 思维导图
【科普向】5G核心网架构和关键技术
Automatic translation software - batch batch automatic translation software recommendation
【C语言项目合集】这十个入门必备练手项目,让C语言对你来说不再难学!
【Go】Go 语言切片(Slice)
R——避免使用 col=0
tidyverse笔记——管道函数
事务的传播机制
【面试:并发篇38:多线程:线程池】ThreadPoolExecutor类的基本概念
电脑开机密码怎么设置?如何给你的电脑加上“安全锁”
【解决】npm ERR A complete log of this run can be found in npm ERR
2022.07.29_每日一题
Jobject 使用
Yu Mr Series 】 【 2022 July 022 - Go Go teaching course of container in the dictionary
深度学习通信领域相关经典论文、数据集整理分享
知识、创新、回报。
Install the gstreamer development dependency library to the project sysroot directory
线程中断方法