当前位置:网站首页>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)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。时间空间复杂度

边栏推荐
- TypeError: 'str' object does not support item assignment
- 【C语言笔记分享】——动态内存管理malloc、free、calloc、realloc、柔性数组
- Build ZABBIX monitoring service in LNMP architecture
- Mmdrawercontroller first loading sidebar height problem
- 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
- DDD based on ABP -- Entity creation and update
- Bibliometrix: dig out the one worth reading from thousands of papers!
- Regular expression and bypass cases
- Video game design report template and
- [oauth2] IV. oauth2authorizationrequestredirectfilter
猜你喜欢

Introduction to Xiaoxiong school
![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](/img/25/aa9bcb6483bb9aa12ac3730cd87368.png)
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

Matlab program for natural gas flow calculation

2022.7.22 simulation match

Meaning of 7 parameters of thread pool

“00后”来了!数睿数据迎来新生代「无代码」生力军
![Rasa 3.x 学习系列-Rasa [3.2.4] - 2022-07-21 新版本发布](/img/1e/27f107d514ded6641410cc5a45764b.png)
Rasa 3.x 学习系列-Rasa [3.2.4] - 2022-07-21 新版本发布

OWASP zap security testing tool tutorial (Advanced)

Not configured in app.json (uni releases wechat applet)

Don't lose heart. The famous research on the explosive influence of Yolo and PageRank has been rejected by the CS summit
随机推荐
Number of bytes occupied by variables of type char short int in memory
Not configured in app.json (uni releases wechat applet)
C language large and small end mode judgment function
字符串——459. 重复的子字符串
Don't lose heart. The famous research on the explosive influence of Yolo and PageRank has been rejected by the CS summit
Nmap security testing tool tutorial
Solve the problem of repeated clicking of button uibutton
栈与队列——20. 有效的括号
Learn science minimize
Unity 委托 (Delegate) 的简单理解以及实现
Detailed analysis of common command modules of ansible service
C multithreaded lock collation record
Stack and queue - 20. Valid parentheses
茅台冰淇淋“逆势”走红,跨界之意却并不在“卖雪糕”
mysql
C language -- three ways to realize student information management
Caffe framework and production data source for deep learning
Rasa 3.x 学习系列-Rasa FallbackClassifier源码学习笔记
ISPRS2018/云检测:Cloud/shadow detection based on spectral indices for multi/hyp基于光谱指数的多/高光谱光学遥感成像仪云/影检测
[oauth2] III. interpretation of oauth2 configuration