各行の最も右の 1 のところを移動する。
class FlipGame { public: int minOperations(vector <string> B) { const int H = B.size(); const int W = B[0].size(); int cnt = 0; while (true) { int mx = -1; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (B[i][j] == '1') mx = max(mx, j); } for (int j = 0; j <= mx; ++j) { B[i][j] = '0' + (B[i][j] == '0'); } } if (mx == -1) break; ++cnt; } return cnt; } };