We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
这道题是双周赛第三题。
看完题目,要知道关键的两点:
我做的时候两点都没想明白
class Solution { public int maximumWhiteTiles(int[][] tiles, int carpetLen) { long res = 0; // sort Arrays.sort(tiles, Comparator.comparingInt(a -> a[0])); long sq = 0; int l = 0; int r = 0; int n = tiles.length; while (r < n && l < n) { if (tiles[l][0] + carpetLen - 1 > tiles[r][1]) { sq += (tiles[r][1] - tiles[r][0] + 1); res = Math.max(res, sq); ++r; } else { if (tiles[l][0] + carpetLen - 1 >= tiles[r][0]) { res = Math.max(res, sq + (tiles[l][0] + carpetLen - tiles[r][0])); } if (tiles[l][0] + carpetLen - 1 > tiles[l][1]) { sq -= (tiles[l][1] - tiles[l][0] + 1); } else { sq -= (carpetLen); } ++l; r = Math.max(r, l); } } return (int)res; } }
参考资料:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
这道题是双周赛第三题。
看完题目,要知道关键的两点:
我做的时候两点都没想明白参考资料:
The text was updated successfully, but these errors were encountered: