摘要: 非递减子序列 class Solution { public: void backtracking(vector &nums, int start) { if(path.size() > 1) { ret.push_back(path); } if(start == nums.size()) { r 阅读全文
posted @ 2024-09-09 11:47 ikun1111 阅读(13) 评论(0) 推荐(0)
摘要: 复原IP地址 class Solution { public: bool isValid(string s, int start, int end) { if (start > end) { return false; } if (s[start] == '0' && start != end) { 阅读全文
posted @ 2024-09-09 10:46 ikun1111 阅读(13) 评论(0) 推荐(0)
摘要: 1, 组合总和 class Solution { public: void backtracking(vector &candidates, int target, int sum, int start) { if(sum > target) { return; } if(sum == target 阅读全文
posted @ 2024-09-09 10:14 ikun1111 阅读(15) 评论(0) 推荐(0)
摘要: 1.组合 class Solution { public: void backtracking(int n, int k, int start) { if(path.size() == k) { ret.push_back(path); return; } for(int i = start; i 阅读全文
posted @ 2024-09-09 09:51 ikun1111 阅读(11) 评论(0) 推荐(0)
摘要: 修剪二叉搜索树 /** Definition for a binary tree node. struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), right(n 阅读全文
posted @ 2024-09-08 22:38 ikun1111 阅读(11) 评论(0) 推荐(0)
摘要: 1.二叉搜索树的最近公共祖先 /** Definition for a binary tree node. struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x), left(NULL) 阅读全文
posted @ 2024-09-08 22:26 ikun1111 阅读(15) 评论(0) 推荐(0)
摘要: 二叉搜素树的最小绝对差 /** Definition for a binary tree node. struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), rig 阅读全文
posted @ 2024-09-08 21:11 ikun1111 阅读(21) 评论(0) 推荐(0)
摘要: 最大二叉树 class Solution { public: int getmax(vector &vec) { int index = 0; int max = INT_MIN; for(int i = 0; i < vec.size(); ++i) { if(max < vec[i]) { ma 阅读全文
posted @ 2024-08-30 21:34 ikun1111 阅读(10) 评论(0) 推荐(0)
摘要: 树左下角值 class Solution { public: void traversal(TreeNode root, int depth, int &ret, int &maxdepth) { if(root->left == nullptr && root->right == nullptr) 阅读全文
posted @ 2024-08-30 21:22 ikun1111 阅读(8) 评论(0) 推荐(0)
摘要: 平衡二叉树 class Solution { public: int getheight(TreeNode *root) { if(root == nullptr) { return 0; } int left = getheight(root->left); int right = getheig 阅读全文
posted @ 2024-08-30 21:09 ikun1111 阅读(14) 评论(0) 推荐(0)