当前位置:网站首页>LeetCode·每日一题·1184.公交站间的距离·模拟
LeetCode·每日一题·1184.公交站间的距离·模拟
2022-07-24 14:21:00 【小迅想变强】
链接:https://leetcode.cn/problems/distance-between-bus-stops/solution/by-xun-ge-v-p073/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
题目

示例

思路
解题思路
模拟
直接按照题目给定要求进行模拟即可
遍历数组,枚举区间start - destination的元素并且累加保存为min,在枚举区间destination - start的元素并且累加保存为max,判断min和max的大小并输出
代码
int distanceBetweenBusStops(int* distance, int distanceSize, int start, int destination){
int max = 0;
int min = 0;
if(start > destination)//方便遍历枚举
{
int t = destination;
destination = start;
start = t;
}
for(int i = start; i < destination; i++)//遍历区间start - destination
{
min += distance[i];
}
for(int i = destination; i != start;)//遍历区间destination - start
{
max += distance[i];
i++;
i = i % distanceSize;
}
return max > min ? min : max;
}
作者:xun-ge-v
链接:https://leetcode.cn/problems/distance-between-bus-stops/solution/by-xun-ge-v-p073/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。时间空间复杂度

边栏推荐
- C operator priority memory formula
- Mmdrawercontroller first loading sidebar height problem
- The solution to the error of [installation detects that the primary IP address of the system is the address assigned by DHCP] when installing Oracle10g under win7
- 正则表达和绕过案例
- Video game design report template and resources over the years
- Bibliometrix: dig out the one worth reading from thousands of papers!
- The spiral matrix of the force buckle rotates together (you can understand it)
- Su Chunyuan, founder of science and technology · CEO of Guanyuan data: making business use is the key to the Bi industry to push down the wall of penetration
- Is it safe for Huatai Securities to open an account? Can it be handled on the mobile phone?
- After five years of contact with nearly 100 bosses, as a headhunter, I found that the secret of promotion was only four words
猜你喜欢

Deep learning 1 perceptron and implementation of simple back propagation network

关于构建网络安全知识库方向相关知识的学习和思考

5年接触近百位老板,身为猎头的我,发现升职的秘密不过4个字

Beijing all in one card listed and sold 68.45% of its equity at 352.888529 million yuan, with a premium rate of 84%

TypeError: Cannot read property ‘make‘ of undefined

Moving the mouse into select options will trigger the mouseleave event processing scheme
![[oauth2] III. interpretation of oauth2 configuration](/img/31/90c79dbc91ee15c353ec46544c8efa.png)
[oauth2] III. interpretation of oauth2 configuration

OWASP zap security testing tool tutorial (Advanced)

小熊派 课程导读

Number of bytes occupied by variables of type char short int in memory
随机推荐
Complete set of JS array common operations
Stack and queue - 225. Implement stack with queue
sql server语法—创建数据库
TypeError: 'str' object does not support item assignment
The fourth edition of Zhejiang University probability proves that the uncorrelation of normal distribution random variables is equivalent to independence
Bibliometrix: dig out the one worth reading from thousands of papers!
SQL Server syntax - create database
Number of bytes occupied by variables of type char short int in memory
电赛设计报告模板及
Concurrent programming ----------- set
Unity 委托 (Delegate) 的简单理解以及实现
Not configured in app.json (uni releases wechat applet)
2022年IAA行业品类发展洞察系列报告·第二期
The difference and relation among list, set and map
Rasa 3.x learning series -rasa [3.2.3] - new version released on July 18, 2022
2022.7.22 simulation match
Detailed analysis of common command modules of ansible service
Rasa 3.x 学习系列-Rasa [3.2.3] - 2022-07-18 新版本发布
关于构建网络安全知识库方向相关知识的学习和思考
Stack and queue - 20. Valid parentheses