09 2022 档案

摘要:图解找递推公式 const int N = 20; class Solution { public: int dp[N]; int numTrees(int n) { dp[0] = 1; for (int i = 1; i <= n; i ++) for (int j = 0; j <= i - 阅读全文
posted @ 2022-09-26 09:32 hjy94wo 阅读(11) 评论(0) 推荐(0) 编辑
摘要:二叉搜索树 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值; 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值; 它的左、右子树也分别为二叉搜索树 /** * Definition for a binary tree node. * struct TreeNode { * 阅读全文
posted @ 2022-09-26 09:09 hjy94wo 阅读(13) 评论(0) 推荐(0) 编辑
摘要:const int N = 60; class Solution { public: int dp[N]; int integerBreak(int n) { dp[2] = 1; for (int i = 3; i <= n; i ++) for (int j = 1; j < i; j ++) 阅读全文
posted @ 2022-09-23 10:05 hjy94wo 阅读(15) 评论(0) 推荐(0) 编辑
摘要:dfs(超时) class Solution { public: int res = 0; void dfs(int i, int j, vector<vector<int>>& obstacleGrid) { if (i == obstacleGrid.size() - 1 && j == obs 阅读全文
posted @ 2022-09-22 19:04 hjy94wo 阅读(15) 评论(0) 推荐(0) 编辑
摘要:dfs(超时) class Solution { public: int res = 0; void dfs(int x, int y, int m, int n) { if (x == m && y == n) res ++; if (x + 1 <= m) dfs(x + 1, y, m, n) 阅读全文
posted @ 2022-09-22 16:45 hjy94wo 阅读(14) 评论(0) 推荐(0) 编辑
摘要:动态规划 const int N = 1000; class Solution { public: int dp[N]; int minCostClimbingStairs(vector<int>& cost) { dp[0] = cost[0]; dp[1] = cost[1]; for (int 阅读全文
posted @ 2022-09-22 15:52 hjy94wo 阅读(16) 评论(0) 推荐(0) 编辑
摘要:动态规划 const int N = 50; class Solution { public: int dp[N]; int climbStairs(int n) { dp[0] = 1; dp[1] = 1; for (int i = 2; i <= n; i ++) dp[i] = dp[i - 阅读全文
posted @ 2022-09-22 15:27 hjy94wo 阅读(10) 评论(0) 推荐(0) 编辑
摘要:动态规划 const int N = 40; class Solution { public: int dp[N]; int fib(int n) { dp[1] = 1; for (int i = 2; i <= n; i ++) dp[i] = dp[i - 1] + dp[i - 2]; re 阅读全文
posted @ 2022-09-22 15:15 hjy94wo 阅读(12) 评论(0) 推荐(0) 编辑
摘要:见c++ STL 阅读全文
posted @ 2022-09-19 10:04 hjy94wo 阅读(8) 评论(0) 推荐(0) 编辑
摘要:略 阅读全文
posted @ 2022-09-19 09:56 hjy94wo 阅读(4) 评论(0) 推荐(0) 编辑
摘要:6.1 函数基础 阶乘函数 int fact(int val) { int ret = 1; while (val > 1) ret *= val--; return ret; } int main() { int val = 5; cout << fact(5) << endl; return 0 阅读全文
posted @ 2022-09-17 15:51 hjy94wo 阅读(19) 评论(0) 推荐(0) 编辑
摘要:5.1 简单语句 略 5.2 语句作用域 略 5.3 条件语句 if语句 switch语句 5.4 迭代语句 while语句 for语句 do while语句 5.5 跳转语句 break continue goto 5.6 try语句和异常处理 try catch语块 ![] (https://i 阅读全文
posted @ 2022-09-17 15:01 hjy94wo 阅读(8) 评论(0) 推荐(0) 编辑
摘要:4.1 基础 略 4.2 算术运算符 4.3 逻辑和关系运算符 4.4 赋值运算符 略 4.5 递增和递减 ++i 先自增后运算 i++ 先运算后自增 4.6 成员访问运算符 int main() { string s1 = "a string"; string *pS1 = &s1; cout < 阅读全文
posted @ 2022-09-17 14:34 hjy94wo 阅读(11) 评论(0) 推荐(0) 编辑
摘要:3.1 using声明 略 3.2 string 3.2.1 string定义和初始化 string s1 = "s1"; string s2(10, 'a'); string s3("s3"); string s4 = "s4"; //拷贝初始化 string s5("s5"); //直接初始化 阅读全文
posted @ 2022-09-17 10:46 hjy94wo 阅读(14) 评论(0) 推荐(0) 编辑
摘要:2.1 基本内置类型 包括算术类型和空类型 2.1.1 算术类型 带符号类型和无符号类型 带符号类型:可以表示正数、负数或0 无符号类型:仅能表示大于0的值 2.1.2 类型转换 #include <iostream> int main() { bool b = 42; // b为真 int i = 阅读全文
posted @ 2022-09-16 18:22 hjy94wo 阅读(23) 评论(0) 推荐(0) 编辑
摘要:1.1 简单C++程序 略 1.2 标准输入输出 IO库:iostream #include <iostream> int main() { std::cout << "Hello world" << std::endl; int v1 = 0, v2 = 0; std::cin >> v1 >> 阅读全文
posted @ 2022-09-16 16:05 hjy94wo 阅读(15) 评论(0) 推荐(0) 编辑
摘要://设正整数值为x,那么负整数绝对值为sum - x //target = x - (sum - x) //x = (target + sum) / 2 const int N = 1010; class Solution { public: int dp[N]; int findTargetSum 阅读全文
posted @ 2022-09-13 15:13 hjy94wo 阅读(6) 评论(0) 推荐(0) 编辑
摘要:const int N = 3010; class Solution { public: int dp[N]; int lastStoneWeightII(vector<int>& stones) { int sum = 0; for (int i = 0; i < stones.size(); i 阅读全文
posted @ 2022-09-13 14:45 hjy94wo 阅读(11) 评论(0) 推荐(0) 编辑
摘要:背包问题 01背包 (1). 二维dp #include<iostream> using namespace std; const int N = 1010; int m, n; int V[N], W[N]; int f[N][N]; //f[i][j]表示从i个物品中选,容量不超过j的最大价值 阅读全文
posted @ 2022-09-13 14:44 hjy94wo 阅读(23) 评论(0) 推荐(0) 编辑
摘要:01背包 const int N = 20010; class Solution { public: int dp[N]; bool canPartition(vector<int>& nums) { int sum = 0; for (int i = 0; i < nums.size(); i + 阅读全文
posted @ 2022-09-13 10:52 hjy94wo 阅读(11) 评论(0) 推荐(0) 编辑
摘要:后序遍历 class Solution { public: int dfs(TreeNode* node) { if (node == nullptr) return 0; if (node->left == nullptr && node->right != nullptr) { return 1 阅读全文
posted @ 2022-09-07 09:50 hjy94wo 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int maxDepth(Node* root) { if (root == nullptr) return 0; int depth = 0; for (int i = 0; i < root->children.size(); i ++) { d 阅读全文
posted @ 2022-09-07 09:26 hjy94wo 阅读(13) 评论(0) 推荐(0) 编辑
摘要:前序遍历解法 前序遍历求二叉树深度 class Solution { public: int res = 0; void dfs(TreeNode* root, int depth) { res = res > depth ? res : depth; if (root->left == nullp 阅读全文
posted @ 2022-09-07 09:25 hjy94wo 阅读(15) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2022-09-07 08:54 hjy94wo 阅读(6) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2022-09-07 08:38 hjy94wo 阅读(16) 评论(0) 推荐(0) 编辑
摘要:二叉树种类 满二叉树 完全二叉树(底层连续) 二叉搜索树(节点元素有一定顺序) 平衡二叉搜索树(左子树与右子树高度差绝对值小于) 存储方式 链式存储 线式存储 二叉树的遍历 深度优先遍历 前序遍历 中左右 中序遍历 左中右 后序遍历 左右中 广度优先遍历 层序遍历 迭代法 LeetCode 144 阅读全文
posted @ 2022-09-06 14:59 hjy94wo 阅读(23) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) { unordered_map<int, int> ma 阅读全文
posted @ 2022-09-06 09:35 hjy94wo 阅读(7) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> fourSum(vector<int>& nums, int target) { vector<vector<int>> res; sort(nums.begin(), nums.end()); for (in 阅读全文
posted @ 2022-09-06 09:27 hjy94wo 阅读(12) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool canConstruct(string ransomNote, string magazine) { int record[26] ={0}; //默认值为0 if (magazine.size() < ransomNote.size()) 阅读全文
posted @ 2022-09-05 18:18 hjy94wo 阅读(7) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<vector<int>> threeSum(vector<int>& nums) { sort(nums.begin(), nums.end()); for (int i = 0; i 阅读全文
posted @ 2022-09-05 18:02 hjy94wo 阅读(22) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<int> twoSum(vector<int>& nums, int target) { unordered_map<int, int> map; for (int i = 0; i < nums.size(); i ++) { aut 阅读全文
posted @ 2022-09-05 17:36 hjy94wo 阅读(12) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int getSum(int n) { int sum = 0; while (n) { sum += (n % 10) * (n % 10); n /= 10; } return sum; } bool isHappy(int n) { unord 阅读全文
posted @ 2022-09-05 17:15 hjy94wo 阅读(10) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool record[1010]; vector<int> res; vector<int> intersection(vector<int>& nums1, vector<int>& nums2) { unordered_set<int> set 阅读全文
posted @ 2022-09-05 16:13 hjy94wo 阅读(14) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool isAnagram(string s, string t) { if (s.size() != t.size()) return false; sort(s.begin(), s.end()); sort(t.begin(), t.end( 阅读全文
posted @ 2022-09-05 15:47 hjy94wo 阅读(5) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; int used[10]; void dfs(vector<int>& nums) { if (path.size() == nums.size()) { res. 阅读全文
posted @ 2022-09-05 14:57 hjy94wo 阅读(11) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; bool used[10]; void dfs(vector<int>& nums) { if (path.size() == nums.size()) { res 阅读全文
posted @ 2022-09-05 14:44 hjy94wo 阅读(14) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; int num = -101; void dfs(int start, vector<int>& nums) { if (path.size() > 1) { re 阅读全文
posted @ 2022-09-05 10:51 hjy94wo 阅读(5) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; void dfs(int start, vector<int>& nums) { res.push_back(path); for (int i = start; 阅读全文
posted @ 2022-09-05 10:07 hjy94wo 阅读(10) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; void dfs(int start, vector<int>& nums) { res.push_back(path); for (int i = start; 阅读全文
posted @ 2022-09-05 08:45 hjy94wo 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<string> res; int pointNum; bool isValid(string s, int begin, int end) { if (begin > end) return false; //防止在最后末尾插入. if 阅读全文
posted @ 2022-09-04 15:54 hjy94wo 阅读(23) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<string>> res; vector<string> path; bool is(string s, int start, int end) { for (int i = start, j = end; i < j; 阅读全文
posted @ 2022-09-04 15:00 hjy94wo 阅读(13) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; int sum = 0; void dfs(int start, int k, int n) { if (path.size() > k || sum > n) r 阅读全文
posted @ 2022-09-04 14:34 hjy94wo 阅读(8) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; int sum; void dfs(int start, vector<int>& candidates, int target) { if (sum > targ 阅读全文
posted @ 2022-09-04 09:18 hjy94wo 阅读(22) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector<vector<int>> res; vector<int> path; int sum = 0; void dfs(int start, vector<int>& candidates, int target) { if (sum > 阅读全文
posted @ 2022-09-04 08:51 hjy94wo 阅读(11) 评论(0) 推荐(0) 编辑
摘要:dfs 定义string数组初始化后加; char型 - ‘0’转为int型 class Solution { public: vector<string> res; string path; const string map[10] = { "", "", "abc", "def", "ghi", 阅读全文
posted @ 2022-09-02 16:37 hjy94wo 阅读(16) 评论(0) 推荐(0) 编辑
摘要:dfs class Solution { public: vector<int> path; vector<vector<int>> res; void dfs(int start, int n, int k) { if (path.size() == k) { res.push_back(path 阅读全文
posted @ 2022-09-02 16:11 hjy94wo 阅读(11) 评论(0) 推荐(0) 编辑
摘要:DFS AcWing 842. 排列数字 #include <iostream> using namespace std; const int N = 10; int n; int path[N], st[N]; void dfs(int u) { if (u == n) { for (int i 阅读全文
posted @ 2022-09-02 15:33 hjy94wo 阅读(63) 评论(0) 推荐(0) 编辑
摘要:const int N = 20; class Solution { public: vector<vector<string>> res; bool col[N], dg[N], udg[N]; void dfs(int u, int n, vector<string>& path) { if ( 阅读全文
posted @ 2022-09-02 15:29 hjy94wo 阅读(12) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示