大概需要一年时间希望能做到easy和medium题能半小时内搞定!since 2020-01-01 在家半年也总是不想做,浪费了时间,还以为自己都会,结果一考试,发现自己并不会。唉。
大概再需要一年时间希望能做到hard题能半小时内搞定!
2020梳理
easy
medium
560 Subarray Sum Equals K | Given an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k |
---|---|
[0629] 做过几次还想不出来正确的解题方法 。答案简单,看完答案自己写对了。 | 前缀和、正负数、 |
94 Binary Tree Inorder Traversal | Given a binary tree, return the inorder traversal of its nodes’ values. |
[0629] emmm, 我的天哪,这都能忘。自己写对了,但是左子树会重复添加,需要改变原有的树结构才能对,后面看了完美答案之后自己写写对了。 | 前序遍历:根结点 —> 左子树 —> 右子树 中序遍历:左子树—> 根结点 —> 右子树 后序遍历:左子树 —> 右子树 —> 根结点 |
554. Brick Wall | You want to draw a vertical line from the top to the bottom and cross the least bricks. |
[0704]思路正确,实现上LTE,看过huahua的之后AC了。 | 用hashmap解决问题,数学结论 |
347. Top K Frequent Elements | It’s guaranteed that the answer is unique, in other words the set of the top k frequent elements is unique. |
[0704]自己想的nlogn,忽视了答案唯一这个条件,应该按照频率进行桶排序就好 | 桶排序 |
## Hard
992. Subarrays with K Different Integers | Given an array A of positive integers, call a (contiguous, not necessarily distinct) subarray of A good if the number of different integers in that subarray is exactly K . |
---|---|
emmmmmm, 挺难的,没想出来,看了别人的思路和huahua的,感觉挺巧妙的,有两层巧妙的地方,一个是用最多的k个减去最多k-1个,得到刚刚k个的情况,另一个巧妙的地方是计算最多k个的时候的算法,应该是有 j-i+1这么多新连续数组加入到以j为最末元素的一个数组中。 | (For example, [1,2,3,1,2] has 3 different integers: 1 , 2 , and 3 .)我们还注意到,对于[[2,3]],只需添加** 2 **,我们就可以忽略该重复的子数组。 滑动窗口没有返回“ [2]”,因为窗口扩展到了“ [1,2,1,2,3]”-使窗口无效,然后通过移动“”将窗口压缩为“ [2,3]” 我前进。 这使我们可以跳过那些重复的子数组。 这里是关键 |