1184. Distance Between Bus Stops Easy
1/**
2 * [1184] Distance Between Bus Stops
3 *
4 * A bus has n stops numbered from 0 to n - 1 that form a circle. We know the distance between all pairs of neighboring stops where distance[i] is the distance between the stops number i and (i + 1) % n.
5 *
6 * The bus goes along both directions i.e. clockwise and counterclockwise.
7 *
8 * Return the shortest distance between the given start and destination stops.
9 *
10 *
11 * Example 1:
12 *
13 * <img alt="" src="https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1.jpg" style="width: 388px; height: 240px;" />
14 *
15 *
16 * Input: distance = [1,2,3,4], start = 0, destination = 1
17 * Output: 1
18 * Explanation: Distance between 0 and 1 is 1 or 9, minimum is 1.
19 *
20 *
21 *
22 * Example 2:
23 *
24 * <img alt="" src="https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1-1.jpg" style="width: 388px; height: 240px;" />
25 *
26 *
27 * Input: distance = [1,2,3,4], start = 0, destination = 2
28 * Output: 3
29 * Explanation: Distance between 0 and 2 is 3 or 7, minimum is 3.
30 *
31 *
32 *
33 *
34 * Example 3:
35 *
36 * <img alt="" src="https://assets.leetcode.com/uploads/2019/09/03/untitled-diagram-1-2.jpg" style="width: 388px; height: 240px;" />
37 *
38 *
39 * Input: distance = [1,2,3,4], start = 0, destination = 3
40 * Output: 4
41 * Explanation: Distance between 0 and 3 is 6 or 4, minimum is 4.
42 *
43 *
44 *
45 * Constraints:
46 *
47 *
48 * 1 <= n <= 10^4
49 * distance.length == n
50 * 0 <= start, destination < n
51 * 0 <= distance[i] <= 10^4
52 *
53 */
54pub struct Solution {}
55
56// problem: https://leetcode.com/problems/distance-between-bus-stops/
57// discuss: https://leetcode.com/problems/distance-between-bus-stops/discuss/?currentPage=1&orderBy=most_votes&query=
58
59// submission codes start here
60
61impl Solution {
62 pub fn distance_between_bus_stops(distance: Vec<i32>, start: i32, destination: i32) -> i32 {
63 0
64 }
65}
66
67// submission codes end
68
69#[cfg(test)]
70mod tests {
71 use super::*;
72
73 #[test]
74 fn test_1184() {
75 }
76}
77
Back
© 2025 bowen.ge All Rights Reserved.