Skip to content

Commit cf2cf54

Browse files
authored
Added solution for 2483
1 parent fc7223c commit cf2cf54

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

02483. Minimum Penalty for a Shop.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use std::cmp::max;
2+
3+
impl Solution {
4+
// Consider no penalty as a profit. Calculate profit after each hour and keep track of the hour when maximum profit was accumulated. Return that hour
5+
pub fn best_closing_time(customers: String) -> i32 {
6+
let mut profit = 0;
7+
let mut max_profit = 0;
8+
let mut best_hour_to_close = -1;
9+
for (i, c) in customers.chars().enumerate() {
10+
if c == 'Y' {
11+
profit += 1;
12+
} else {
13+
profit -= 1;
14+
}
15+
if profit > max_profit {
16+
max_profit = profit;
17+
best_hour_to_close = (i as i32);
18+
}
19+
}
20+
return best_hour_to_close + 1;
21+
}
22+
}

0 commit comments

Comments
 (0)