十大排序算法的数组和链表实现 2020-04-22 学习总结 数组排序在牛客,进行测试;链表排序在leetcode进行测试。 发现一个牛逼的数据结构与算法的可视化网站(https://visualgo.n Read more...
[Lc]22括号生成 2020-04-21 leetcode 题目 题解 1.递归法 class Solution { vector<string> res;//在私有变量定义res在存结果, public: vector<string> generateParenthesis(int n) {//两种方法。1.递归 if(n==0) return res;//特殊情况 generateParenthesisDFS(n, n, " Read more...
[Lc]20有效的括号 2020-04-21 leetcode 题目 题解 时间复杂度$O(N)$ 空间复杂度$O(N)$ class Solution { public: bool isValid(string s) {//用栈 //不能挨个比较,因为有可能两个括号是交错的,用栈最合适 stack<char> par Read more...
[Lc]17电话号码的字母组合 2020-04-20 leetcode 题目 题解 时间复杂度$O(3^{N}+4^{M})$,N是有三个字母的数字数量,M是有4个字母的数字数量。 空间复杂度$O(3^{N}+4^{M Read more...
[Lc]14最长公共前缀 2020-04-18 leetcode 题目 题解 1. 遍历法 时间复杂度$O(S)$(最坏情况)。S是所有字符数量。 空间复杂度$O(1)$ class Solution { public: string longestCommonPrefix(vector<string>& strs) {//两种方法。1.遍历法 //这道 Read more...
Cpp数组初始化问题(待续) 2020-04-18 c++ 数组 c++数组主要包括静态数组,动态数组,vector 1. 静态数组 未初始化的数组是随机数据,初始化方法有 int arr[1024] = {0}; //全部初始化为0 int arr[1024] = {1}; // Read more...
[Lc]67二进制求和 2020-04-13 leetcode 题目 题解 按位相加即可,注意字符串与整型的转换,数字小的填0,注意进位 时间复杂度$O(max{(aLen + bLen)})$ 空间复杂度$O(max{(aLen Read more...
[Lc]31下一个排列 2020-04-12 leetcode 题目 题解 这道题不好理解,具体的题解见leetcode和Grandyang class Solution {//这道题不好理解,最好直接记方法 public: void nextPermutation(vector<int>& nums) { int n = nums.size(), i = n-2, j = Read more...
[Lc]60第k个排列 2020-04-11 leetcode 题目 题解 这道题直接找规律,比较难自己想通,该解法出自grandyang class Solution { public: string getPermutation(int n, int k) { string res;//定义res保存结果 string nums = " Read more...