摘要:
方向矩阵 // →为初始方向 int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; for (int i = 1, x = 0, y = 0, d = 0; i <= n * n; i ++ ) { res[x][y] = i; int a = x + dx 阅读全文
摘要:
题目 剑指 Offer 15. 二进制中1的个数 代码 逐位判断 class Solution { public: int hammingWeight(uint32_t n) { int res = 0; while(n) { res += n & 1; n >>= 1; } return res; 阅读全文
摘要:
题目 剑指 Offer 14- II. 剪绳子 II 代码 class Solution { public: int cuttingRope(int n) { if(n <= 3) return 1 * (n - 1); long res = 1; if(n % 3 == 1) res = 4, n 阅读全文