The Array ||
来源:互联网 发布:知乎上面的神回复 编辑:程序博客网 时间:2024/05/01 17:41
Merge Sorted Array.
这个题实现并不难,关键是要从后往前扫,才能保证从后往前存入的时候不会把没有扫到的值覆盖掉。
Subsets 这道题本来没啥好说的,recursion想法和 Combination 题目近似,但是在做的时候偶然发现一个问题:在IntelJ里面追踪res的时候,尽管最后结果对,但过程中res变化不正常,
以nums = [1,2]为例, 如果每次加入res时候不传temp对copy而是传本身,在每次迭代中输出res,结果如下:
[[]]
[[1], [1]]
[[1], [1, 2], [1, 2]]
[[2], [1], [1, 2], [2]]
[[], [1], [1, 2], [2]]
可以看出,最后是对的,但过程但记录是不合理但。如何换位传入 remp对copy,整个过程就合理了
[[]]
[[], [1]]
[[], [1], [1, 2]]
[[], [1], [1, 2], [2]]
最后发现是temp在加入res时候没有copy,尽管在同一层最好的变化是被抵消了吧,但是还是不规范,一定要注意recursion中传参问题。另外附加一种iteration的经典思路,code来自Coder_Ganker大神
Binary search has always been my weakness. However, consider I just seriously start doing algorithm coding problems, bear with it for now. I should take a big lesson from this one. What is A binary search do? --- it always go to left OR right part in next iteration until two sides finally merge. Where does binary search end? --- In last iteration, when l == r, you can either change r or change l, which is both correct or harmless. The question is, I should know clearly which one is finally changing and which one remains in right ending position. In this problem, we do 2 BSs to find right position and left respectively. We want to use ll as l and rr as r, so we modify lr and rl at end of two BSs.
Jump Game : *
Jump Game II : **
Follow up is returning minimum steps needed to reach the last index. The code is also O(n) solution.
Coder_Ganker .... 大神就是大神 。。。记住for循环这种用法
另外还加了一种实现,同样的思路,用的是for + while, 注意for 的用法, 实质是 while + while
- The Array |
- The Array ||
- The Array |||
- Intro:The Array lterator
- B - Sort the Array
- B. Sort the Array
- Sort the Array
- Sort the Array CodeForces
- Sort the Array
- Why the address of array equals array.
- max sub array of the given array
- the trap: c++'s array
- Format the array with hashes
- codeforce-B. Sort the Array
- 451 B. Sort the Array
- Sort the Array+codeforces+水题
- 451B - Sort the Array
- The First (for-each ,Array)
- 过滤器 监听器 拦截器作用
- HDU 1394 Minimum Inversion Number(线段树:单点更新,求逆序数)
- 96Unique Binary Search Trees
- DOM 扩展——JavaScript高级程序设计笔记(9)
- ZOJ 3674 Search in the Wiki(字典树 + map + vector)
- The Array ||
- 6.7Pointers to Functions
- UITextField 弹出键盘的外观(类型)设置
- Unity Asset(4)特性插件 FX Maker
- muuarhmrc
- 黑马程序员——黑苹果的日记(11)—— oc加强
- 慕课学习C笔记01-第1~4章数据类型、运算符和程序结构语句
- 黑马程序员——黑苹果的日记(8)——oc基础之类和对象
- Example-1-MPI_Scatterv and MPI_Gather