摘要: 超时的代码如下,主要思路是使用堆栈存储每个柱子的高度,然后用每一层减去上一个该高度所在位置 思路没问题就是超时了 class Solution { public: int trap(vector<int>& height) { int m =0; int l = height.size(); int 阅读全文
posted @ 2022-02-22 17:33 jozon 阅读(47) 评论(0) 推荐(0)
摘要: 自己使用堆栈没有成功,主要原因是很久没有敲代码,再加上没有演算整个过程,凭空想象,非常的不好 贴自己没成功的代码吧 class Solution { public: int longestValidParentheses(string s) { stack<string>temp; int numb 阅读全文
posted @ 2022-02-21 20:22 jozon 阅读(35) 评论(0) 推荐(0)
摘要: 大三放寒假一个月没有打代码了,简单题不会做,练练手 class Solution { public: int removeElement(vector<int>& nums, int val) { int left =0; int right =nums.size()-1; while(left<= 阅读全文
posted @ 2022-02-21 15:39 jozon 阅读(21) 评论(0) 推荐(0)
摘要: 看了题解写的,然后对于模拟题接触比较少 收获: 对于map的遍历:map<int,int>::iterater iter; iter = map.begin(); while(iter!=map.end(){iter++;} 然后还有map函数,的static_cost<int>()暂时不想追究这是 阅读全文
posted @ 2022-01-16 19:28 jozon 阅读(34) 评论(0) 推荐(0)
摘要: 自主完成,然后看了提示为动态规划,然后就是没有写状态转移方程,花了很多时间调试 查看代码 class Solution: def findTargetSumWays(self, nums: List[int], target: int) -> int: m={} temp=0 m_1={} m_1[ 阅读全文
posted @ 2022-01-09 16:42 jozon 阅读(28) 评论(0) 推荐(0)
摘要: 前缀和+哈希表,将部分和表示为前缀,向后移动,得到目标便加1 class Solution: def subarraySum(self, nums: List[int], k: int) -> int: count = 0; m={0:1} temp=0; for i in nums: temp+= 阅读全文
posted @ 2022-01-08 16:32 jozon 阅读(29) 评论(0) 推荐(0)
摘要: 这是单调栈的经典应用,第一次接触,因为简单,就是栈中元素按照排序顺序存储 超时是忘记删除输出测试语句了 class Solution: def dailyTemperatures(self, temperatures: List[int]) -> List[int]: a=list() result 阅读全文
posted @ 2022-01-07 12:49 jozon 阅读(37) 评论(0) 推荐(0)
摘要: 黔驴技穷,思路记录一下(虽然超时了):使用哈希表standard保存p字符串中字符极其数量,然后使用temp复制一份 然后依次读入s字符串,读入一个则减去temp中的一个,如果某一项减为0了,则放弃,从first中开始,保存每个字符串在当前扫描字符串的位置 查看代码 class Solution{ 阅读全文
posted @ 2022-01-06 13:36 jozon 阅读(41) 评论(0) 推荐(0)
摘要: 期末每日打卡,约瑟夫环,明日学习 阅读全文
posted @ 2022-01-04 20:35 jozon 阅读(15) 评论(0) 推荐(0)
摘要: 这道题做了很多遍了,在字节训练营笔试做过,虽然那次只做对了两道题目 这是深度遍历,没什么好说的,每个结点都深度遍历一遍,用队列保存每个结点,依次遍历,想不到效率还行 查看代码 /** * Definition for a binary tree node. * struct TreeNode { * 阅读全文
posted @ 2022-01-03 12:35 jozon 阅读(36) 评论(0) 推荐(0)