Skip to content

Commit 5d362b3

Browse files
committed
Runtime: 1 ms (Top 88.7%) | Memory: 39.44 MB (Top 55.0%)
1 parent 16fad30 commit 5d362b3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Runtime: 1 ms (Top 88.7%) | Memory: 39.44 MB (Top 55.0%)
2+
3+
class Solution {
4+
public int minCostSetTime(int startAt, int moveCost, int pushCost, int tar) {
5+
6+
int min=tar/60, sec=tar%60, minCost=(moveCost+pushCost)*4;
7+
8+
if(min>99) { min--; sec+=60; } // this is required to do because if tar>=6000 then min is 100 which is not possible as it atmost can be 99mins
9+
10+
while(min>=0&&sec<=99) { // this while loop will work for atmost 2 iterations
11+
tar=min*100+sec;
12+
char arr[]=(""+tar).toCharArray();
13+
int sameMove=0;
14+
for(int i=0;i<arr.length-1;i++)
15+
if(arr[i]==arr[i+1])
16+
sameMove++;
17+
if(startAt==arr[0]-'0')
18+
minCost=Math.min(minCost,pushCost*arr.length+moveCost*(arr.length-1-sameMove));
19+
else
20+
minCost=Math.min(minCost,pushCost*arr.length+moveCost*(arr.length-sameMove));
21+
min--; sec+=60;
22+
}
23+
return minCost;
24+
}
25+
}

0 commit comments

Comments
 (0)