![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
洛星洛
迈步前行
展开
-
链表习题(剑指offer)
1、第一题方法1:/*** struct ListNode {* int val;* struct ListNode *next;* ListNode(int x) :* val(x), next(NULL) {* }* };*/class Solution {public: vector<int> printListFromTailToHead(ListNode* head)原创 2021-04-14 20:33:50 · 145 阅读 · 0 评论 -
二叉树练习
第一题:重建二叉树/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* reConstructBinaryT原创 2021-04-20 22:46:00 · 276 阅读 · 0 评论 -
数组练习
第一题:二维数组中查找class Solution {public: bool Find(int target, vector<vector<int> > array) { //行 for(int i=0;i<array.size();i++) { //列 for(int j=0;j<array[0].size();j++) {原创 2021-04-28 14:19:31 · 352 阅读 · 0 评论 -
字符串练习
第一题:替换空格class Solution {public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return string字符串 */ string replaceSpace(string s) { // write code here string res; for原创 2021-05-17 22:16:30 · 172 阅读 · 0 评论 -
栈练习
第一题:用两个栈实现队列class Solution{public: void push(int node) { stack1.push(node); } int pop() { if(stack2.empty()){ while(!stack1.empty()){ stack2.push(stack1.top()); stack1.pop();原创 2021-05-26 17:03:16 · 176 阅读 · 0 评论 -
递归练习
递归三要素:1、确定递归函数的参数和返回值2、确定终止条件3、确定单层递归的逻辑第一题:斐波那切数列class Solution {public: int Fibonacci(int n) { int a1=0,a2=1; return res(a1,a2,n); } int res(int a1, int a2, int num){ if(num == 0) return a1; if(num ==原创 2021-05-27 15:16:38 · 176 阅读 · 0 评论 -
剑指offer其它练习
1、二进制中1的个数class Solution {public: int NumberOf1(int n) { int res = 0; unsigned int un = n; while(un) res += un & 1, un >>= 1; return res; }};2、数值的整数次方class Solution {public: double Powe原创 2021-06-05 17:02:01 · 98 阅读 · 0 评论 -
回溯法练习
第一题:矩阵中的路径原创 2021-06-03 22:06:13 · 202 阅读 · 0 评论