摘要: 翻转二叉树 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 阅读(10) 评论(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)
摘要: 四数相加 class Solution { public: int fourSumCount(vector& nums1, vector& nums2, vector& nums3, vector& nums4) { unordered_map<int, int> umap; for(int num 阅读全文
posted @ 2024-08-20 20:22 ikun1111 阅读(8) 评论(0) 推荐(0)
摘要: 有效的字母异位词 class Solution { public: bool isAnagram(string s, string t) { int record[26] = {0}; for(int i = 0; i < s.size(); ++i) { record[s[i] - 'a']++; 阅读全文
posted @ 2024-08-19 20:40 ikun1111 阅读(39) 评论(0) 推荐(0)
摘要: 两两交换链表中的节点 一开始有错误,找不出来,但是gdb真好用 Definition for singly-linked list. struct ListNode { int val; ListNode *next; ListNode() : val(0), next(nullptr) {} Li 阅读全文
posted @ 2024-08-19 20:31 ikun1111 阅读(39) 评论(0) 推荐(0)
摘要: 203 移除链表元素 /** Definition for singly-linked list. struct ListNode { int val; ListNode *next; ListNode() : val(0), next(nullptr) {} ListNode(int x) : v 阅读全文
posted @ 2024-08-19 20:19 ikun1111 阅读(52) 评论(0) 推荐(0)
摘要: 209.长度最小的数组 使用滑动窗口,这个方法我是没有想到的 class Solution { public: int minSubArrayLen(int target, vector& nums) { int i = 0; int min = nums.size()+1; int j = 0; 阅读全文
posted @ 2024-08-19 20:09 ikun1111 阅读(46) 评论(0) 推荐(0)