leetcode:Permutations1+2 + Rotat…
来源:互联网 发布:阿里云备案网站名称 编辑:程序博客网 时间:2024/06/05 15:30
Permutations1:
给定数组如[1,2,3],找出所有排列。用回溯法即可,关键在于迭代器的应用,我们可以用迭代器暂时把入栈的元素从数组中删除,这样就能很方便的用深搜来遍历数组了。
Permutations2:
数组中这次有了重复元素,解决方法很简单,在入栈之前做个判断,如果等于上一个元素,说明不用考虑(这种情况已经遍历过了)。关键是验证了一种方法,迭代器可以加减常量:ite==*(ite-1)
Rotate Image:
把矩阵顺时针旋转90度,题目不难,难的是要不用额外空间。这里直接粘贴大神的方法:
* first reverse up to down, then swap the symmetry
* 1 2 3 7 8 9 7 4 1
* 4 5 6 => 4 5 6 => 8 5 2
* 7 8 9 1 2 3 9 6 3
对角旋转90度,再水平翻转,真心逆天。。
阅读全文
0 0
- leetcode:Permutations1+2 + Rotat…
- leetcode:Remove Element + Imple…
- leetcode:Divide Two Integers + …
- leetcode:Shuffle an Array + Miss…
- leetcode:Integer to Roman + Fin…
- leetcode:Single Number123 …
- leetcode:Reconstruct Original D…
- leetcode:Multiply Strings +…
- leetcode:Next Permutation + Lon…
- leetcode:Fraction to Recurring …
- leetcode:Linked List Random Node…
- leetcode:Bulb Switcher + K…
- leetcode:Pow(x, n) + N-Quee…
- Struts 2 + Spring 2.0 + Hibernat…
- Picture of my baby when 2 monthe…
- 集线器 交换机 路由器 网桥 …
- 使用BBED修改SCN …
- leetcode:Longest Increasing…
- 【linux 解压】Centos下解压rar、zip文件的方法
- leetcode:Gray Code +&n…
- leetcode:Maximum Subarray+Find M…
- leetcode:Longest Increasing…
- leetcode:Multiply Strings +…
- leetcode:Permutations1+2 + Rotat…
- 用已有的caffemodel和python脚本进…
- leetcode:Pow(x, n) + N-Quee…
- linux中$* $@ 以及各自…
- leetcode:Simplify Path+Edit…
- C++虚函数的内存管理
- visual studio无法查看局部变…
- 将博客搬至CSDN
- 着色语言 Shading Language(二)