# LeetCode - 0554. Brick Wall ### 題目網址:https://leetcode.com/problems/brick-wall/ ###### tags: `LeetCode` `Medium` `排序(Sorting)` ```cpp= /* -LeetCode format- Problem: 554. Brick Wall Difficulty: Medium by Inversionpeter */ static const auto Initialize = []{ ios::sync_with_stdio(false); cout.tie(nullptr); return nullptr; }(); int brickEnds[20000], bricks; class Solution { public: int leastBricks(vector<vector<int>>& wall) { int sums, nowEnd, counts, maximum = 0; bricks = counts = nowEnd = 0; for (int i = 0; i != wall.size(); ++i) { sums = 0; for (int j = 0; j != wall[i].size(); ++j) { sums += wall[i][j]; brickEnds[bricks] = sums; ++bricks; } } sort(brickEnds, brickEnds + bricks); for (int i = 0; i < bricks; ++i) if (nowEnd != brickEnds[i]) { maximum = max(maximum, counts); nowEnd = brickEnds[i]; counts = 1; } else ++counts; return wall.size() - maximum; } }; ```