2483.cpp (349B)
1 class Solution { 2 public: 3 int bestClosingTime(string customers) { 4 int mini = 0, crnt = 0, res = 0; 5 6 for (int i = 0; i < customers.size(); i++) { 7 crnt += (customers[i] == 'Y') ? -1 : +1; 8 if (crnt >= mini) continue; 9 res = i + 1; 10 mini = crnt; 11 } 12 13 return res; 14 } 15 };