摘要: 最大二叉树 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)
摘要: 翻转二叉树 class Solution { public: void traversal(TreeNode root) { if(root == nullptr) { return; } traversal(root->left); traversal(root->right); TreeNode 阅读全文
posted @ 2024-08-30 20:58 ikun1111 阅读(13) 评论(0) 推荐(0)
摘要: 递归遍历 前序遍历 /** Definition for a binary tree node. struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(0), left(nullptr), right 阅读全文
posted @ 2024-08-30 20:47 ikun1111 阅读(18) 评论(0) 推荐(0)
摘要: 用栈实现队列 class MyQueue { public: MyQueue() {} void push(int x) { stIn.push(x); } int pop() { int a; while(!stIn.empty()) { a = stIn.top(); stIn.pop(); s 阅读全文
posted @ 2024-08-30 20:39 ikun1111 阅读(16) 评论(0) 推荐(0)
摘要: 反转字符串中的单词 class Solution { public: string reverseWords(string s) { int slow = 0; int i = 0; while(i < s.size()) { if(s[i] != ' ') { if(slow != 0) { s[ 阅读全文
posted @ 2024-08-30 20:22 ikun1111 阅读(11) 评论(0) 推荐(0)
摘要: 反转字符串 利用双指针不断向中间靠拢, 交换数据 class Solution { public: void reverseString(vector& s) { int left = 0; int right = s.size() - 1; while(left < right) { char t 阅读全文
posted @ 2024-08-30 19:51 ikun1111 阅读(10) 评论(0) 推荐(0)