摘要: 修改CMakeLists.txt内容 cmake_minimum_required(VERSION 3.23) project(test) set(CMAKE_CXX_STANDARD 14) #上面三行无需改动 #递归遍历所有的cpp文件 file (GLOB_RECURSE files *.cp 阅读全文
posted @ 2022-11-26 10:15 当惜 阅读(136) 评论(0) 推荐(0)
摘要: 方向矩阵 // →为初始方向 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 阅读全文
posted @ 2022-10-25 10:11 当惜 阅读(24) 评论(0) 推荐(0)
摘要: 题目 剑指 Offer 18. 删除链表的节点 代码 class Solution { public: ListNode* deleteNode(ListNode* head, int val) { if(head->val == val) return head->next; auto pre = 阅读全文
posted @ 2022-04-21 15:27 当惜 阅读(11) 评论(0) 推荐(0)
摘要: 题目 剑指 Offer 17. 打印从1到最大的n位数 代码 傻瓜做法(不考虑大数) class Solution { public: vector<int> printNumbers(int n) { int sum = 1; vector<int> res; for(int i = 0; i < 阅读全文
posted @ 2022-04-21 15:06 当惜 阅读(17) 评论(0) 推荐(0)
摘要: 题目 剑指 Offer 16. 数值的整数次方 代码 阅读全文
posted @ 2022-04-20 16:15 当惜 阅读(17) 评论(0) 推荐(0)
摘要: 题目 剑指 Offer 15. 二进制中1的个数 代码 逐位判断 class Solution { public: int hammingWeight(uint32_t n) { int res = 0; while(n) { res += n & 1; n >>= 1; } return res; 阅读全文
posted @ 2022-04-20 15:53 当惜 阅读(17) 评论(0) 推荐(0)
摘要: 题目 剑指 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 阅读全文
posted @ 2022-04-20 15:24 当惜 阅读(14) 评论(0) 推荐(0)
摘要: 题目 剑指 Offer 14- I. 剪绳子 分析 绳子切分方案 乘积 结论 2=1+1 1×1=1 3=1+2 1×2=2 4=2+2=1+3 2×2=4>1×3=3 4 和 2 等价,且 2+2 比 1+3 更优 5=2+3=1+4 2×3=6>1×4=4 6=3+3=2+2+2 3×3=9>2 阅读全文
posted @ 2022-04-20 15:14 当惜 阅读(19) 评论(0) 推荐(0)
摘要: 题目 剑指 Offer 13. 机器人的运动范围 代码 阅读全文
posted @ 2022-04-19 21:31 当惜 阅读(10) 评论(0) 推荐(0)
摘要: 题目 剑指 Offer 12. 矩阵中的路径 代码 class Solution { public: bool exist(vector<vector<char>>& board, string word) { for(int i =0; i < board.size(); i++) for(int 阅读全文
posted @ 2022-04-19 16:29 当惜 阅读(14) 评论(0) 推荐(0)
点击右上角即可分享
微信分享提示