File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 831
831
| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | [](src/SemiOrderedPermutation.java) | |
832
832
| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | |
833
833
| 2729 | [Check if The Number is Fascinating](https://leetcode.com/problems/check-if-the-number-is-fascinating) | [](src/CheckIfTheNumberIsFascinating.java) | |
834
- | 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [](src/NeitherMinimumNorMaximum.java ) | |
835
- | 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | | |
834
+ | 2733 | [Neither Minimum nor Maximum](https://leetcode.com/problems/neither-minimum-nor-maximum) | [](src/NeitherMinimumNorMaximum.java) | |
835
+ | 2739 | [Total Distance Traveled](https://leetcode.com/problems/total-distance-traveled) | [](src/TotalDistanceTraveled.java) | |
836
836
| 2744 | [Find Maximum Number of String Pairs](https://leetcode.com/problems/find-maximum-number-of-string-pairs) | | |
837
837
| 2748 | [Number of Beautiful Pairs](https://leetcode.com/problems/number-of-beautiful-pairs) | | |
838
838
| 2760 | [Longest Even Odd Subarray With Threshold](https://leetcode.com/problems/longest-even-odd-subarray-with-threshold) | | |
Original file line number Diff line number Diff line change
1
+ // https://leetcode.com/problems/total-distance-traveled
2
+ // M = mainTank
3
+ // T: O(M)
4
+ // S: O(1)
5
+
6
+ public class TotalDistanceTraveled {
7
+ public int distanceTraveled (int mainTank , int additionalTank ) {
8
+ int totalDistance = 0 ;
9
+ while (mainTank > 0 ) {
10
+ if (mainTank >= 5 ) {
11
+ mainTank -= 5 ;
12
+ totalDistance += 50 ;
13
+ if (additionalTank > 0 ) {
14
+ mainTank ++;
15
+ additionalTank --;
16
+ }
17
+ } else {
18
+ totalDistance += mainTank * 10 ;
19
+ mainTank = 0 ;
20
+ }
21
+ }
22
+
23
+ return totalDistance ;
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments