-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.cs
More file actions
56 lines (49 loc) · 1.82 KB
/
Solution.cs
File metadata and controls
56 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace LeetCode.Problem2224{
//2224. Minimum Number of Operations to Convert Time
//https://leetcode.com/problems/minimum-number-of-operations-to-convert-time/
/*
You are given two strings current and correct representing two 24-hour times.
24-hour times are formatted as "HH:MM", where HH is between 00 and 23, and MM is between 00 and 59.
The earliest 24-hour time is 00:00, and the latest is 23:59.
In one operation you can increase the time current by 1, 5, 15, or 60 minutes. You can perform this operation any number of times.
Return the minimum number of operations needed to convert current to correct.
*/
public class Solution {
public int ConvertTime(string current, string correct) {
var hourCurrent =int.Parse(current.Split(':')[0]);
var hourCorrect = int.Parse(correct.Split(':')[0]);
var minCurrent = int.Parse(current.Split(':')[1]);
var minCorrect = int.Parse(correct.Split(':')[1]);
var currentTime = hourCurrent * 60 + minCurrent;
var correctTime = hourCorrect * 60 + minCorrect;
int steps = 0;
if (currentTime == correctTime)
{
return 0;
}
while (currentTime != correctTime)
{
switch ((correctTime - currentTime) / 5)
{
case >= 12 :
steps++;
currentTime+=60;
break;
case >= 3 :
steps++;
currentTime+=15;
break;
case >= 1:
steps++;
currentTime+=5;
break;
case 0 :
steps++;
currentTime+=1;
break;
}
}
return steps;
}
}
}