摘要: 题目链接:牛客题霸--子数组的最大累加和问题 来源:牛客网 《数据结构》最大子列和模板题, 时间复杂度 O(n) class Solution { public: int maxsumofSubarray(vector<int>& arr) { int maxn = 0, thismaxn = 0; 阅读全文
posted @ 2020-11-07 00:55 182天后可以改名 阅读(51) 评论(0) 推荐(0)
摘要: 题目链接:牛客题霸--两数之和 来源:牛客网 暴力搜索一下, 时间复杂度 O( 小于 n^2) class Solution { public: vector<int> twoSum(vector<int>& numbers, int target) { vector<int>vec; for ( 阅读全文
posted @ 2020-11-07 00:43 182天后可以改名 阅读(58) 评论(0) 推荐(0)
摘要: 题目链接:牛客题霸--括号匹配 来源:牛客网 用栈的性质来解题 当栈为空时: 把字符入栈 不为空时: 比较当前元素和栈顶是否匹配, 如果匹配, 则出栈 最后判断栈中的元素就是不可匹配的字符 class Solution { public: bool isValid(string s) { stack 阅读全文
posted @ 2020-11-07 00:29 182天后可以改名 阅读(89) 评论(0) 推荐(0)
摘要: 题目链接:牛客题霸--用两个栈实现队列 来源:牛客网 思路: 入栈时: 栈 1 入栈 出栈时: 一. 把栈 1 的元素存入栈 2 二. 把栈 2 的 top 存入一个变量Top中 三. 把栈 2 的元素再倒回栈 1 四. 返回 Top (就是队首元素)的值 class Solution { publ 阅读全文
posted @ 2020-11-07 00:08 182天后可以改名 阅读(17) 评论(0) 推荐(0)
摘要: 题目链接:牛客题霸--跳台阶 来源:牛客网 算出前几项就可以找到此规律 class Solution { public: int jumpFloor(int number) { int a[10010]; a[0] = 0, a[1] = 1, a[2] = 2; for ( int i = 3; 阅读全文
posted @ 2020-11-06 23:43 182天后可以改名 阅读(34) 评论(0) 推荐(0)
摘要: 题目链接牛客题霸--最长回文子串题解 来源:牛客网 马拉车算法求最长回文子串 class Palindrome { public: int getLongestPalindrome(string A, int n) { string str = "@#"; int p[100010], id = 0 阅读全文
posted @ 2020-11-06 13:34 182天后可以改名 阅读(79) 评论(0) 推荐(0)
摘要: 题目链接:牛客题霸--反转字符串 来源:牛客网 暴力, 原始字符串取反存入新字符串 class Solution { public: string solve(string str) { string reverse_str; for ( int i = str.size()-1; i >= 0; 阅读全文
posted @ 2020-11-06 13:17 182天后可以改名 阅读(76) 评论(0) 推荐(0)