C# 代码
public class Solution {
public int BestClosingTime(string customers) {
int n = customers.Length;
int cost = 0;
for (int i = 0; i < n; i++){
if (customers[i] == 'Y') cost++;
}
int minCost = cost;
int result = 0;
for (int i = 0; i < n; i++){
if (customers[i] == 'N'){
cost++;
}
else {
cost--;
if (cost < minCost){
cost = minCost;
result = i + 1;
}
}
}
return result;
}
}