摘要: 145. 二叉树的后序遍历 思路: \(dfs\) 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode( 阅读全文
posted @ 2020-09-29 21:54 nonameless 阅读(117) 评论(0) 推荐(0) 编辑
摘要: 113. 路径总和 II 思路: \(dfs\) 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(i 阅读全文
posted @ 2020-09-27 00:33 nonameless 阅读(66) 评论(0) 推荐(0) 编辑
摘要: 106. 从中序与后序遍历序列构造二叉树 思路: 根据后序遍历的最后一个元素是根的性质逐步构造出二叉树。 代码: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * T 阅读全文
posted @ 2020-09-26 12:49 nonameless 阅读(96) 评论(0) 推荐(0) 编辑
摘要: Aerodynamic 思路: 判断一个图形是否是中心对称图形。 \(n\) 是奇数,显然不行。 \(n\) 是偶数。找出对应点对的中心。如果是对称的,那么一定会相交于一点。 代码: int n; cin >> n; vector<PII> point(n + 1); vector<PDD> cen 阅读全文
posted @ 2020-09-25 00:54 nonameless 阅读(71) 评论(0) 推荐(0) 编辑
摘要: 题目链接 A. Cubes Sorting 思路: 根据可交换的次数可以看出:直接判断数组是否是递减的即可。 代码: const int N = 1e5 + 10; int a[N]; int main(){ int t; cin >> t; while(t --){ int n; cin >> n 阅读全文
posted @ 2020-09-25 00:44 nonameless 阅读(122) 评论(0) 推荐(0) 编辑
摘要: Anu Has a Function 思路: \(f(x, y) = x | y - y\)。将 \(x, y\) 对齐。那么结果就是:如果 \(y\) 的第 \(i\) 是 $1$,那么把 \(x\) 的第 \(i\) 位变为 $0$(无论之前是什么)。那么根据这个性质可以发现,改变的都是第 $1 阅读全文
posted @ 2020-09-24 07:59 nonameless 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 1. 两数之和 思路: 暴力遍历 代码: class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { int lenNums = nums.size(); int a, b; for(int i = 0; 阅读全文
posted @ 2020-09-23 15:42 nonameless 阅读(140) 评论(0) 推荐(0) 编辑
摘要: 题目链接 A - Decrease the Sum of Digits 思路: 记录以下到那个位置会大于 \(s\),然后前一个位置的数加一,之后的全部变为零即可。 注意特判到某个位置刚好等于 \(s\) 的情况。 代码: int main(){ int t; cin >> t; while(t - 阅读全文
posted @ 2020-09-23 15:36 nonameless 阅读(161) 评论(0) 推荐(1) 编辑
摘要: 题目链接 A - Plural Form /* * @Author : nonameless * @Date : 2020-09-19 20:00:41 * @LastEditors : nonameless * @LastEditTime : 2020-09-19 20:05:21 */ #inc 阅读全文
posted @ 2020-09-19 21:37 nonameless 阅读(215) 评论(2) 推荐(2) 编辑
摘要: 题目链接 A. Buying Torches 思路: 直接计算出需要的木棍,然后取除以 \((x -1)\)(向上取整),最后在加上 \(k\) 即可。 代码: /* * @Author : nonameless * @Date : 2020-09-14 22:22:07 * @LastEditor 阅读全文
posted @ 2020-09-15 02:30 nonameless 阅读(388) 评论(0) 推荐(2) 编辑