提交 4acb8f3c 编写于 作者: L labuladong

update content

上级 2a4efc4f
pictures/plugin/全家桶.jpg

144.5 KB | W: | H:

pictures/plugin/全家桶.jpg

389.7 KB | W: | H:

pictures/plugin/全家桶.jpg
pictures/plugin/全家桶.jpg
pictures/plugin/全家桶.jpg
pictures/plugin/全家桶.jpg
  • 2-up
  • Swipe
  • Onion skin
......@@ -20,6 +20,7 @@
| [225. Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues/) | [225. 用队列实现栈](https://leetcode.cn/problems/implement-stack-using-queues/) | 🟢
| [232. Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/) | [232. 用栈实现队列](https://leetcode.cn/problems/implement-queue-using-stacks/) | 🟢
| - | [剑指 Offer 09. 用两个栈实现队列](https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | 🟢
| - | [剑指 Offer 09. 用两个栈实现队列](https://leetcode.cn/problems/yong-liang-ge-zhan-shi-xian-dui-lie-lcof/) | 🟢
**-----------**
......
......@@ -27,7 +27,7 @@
位操作(Bit Manipulation)可以有很多技巧,有一个叫做 Bit Twiddling Hacks 的网站收集了几乎所有位操作的黑科技玩法,网址如下:
http://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
http://graphics.stanford.edu/~seander/bithacks.html
但是这些技巧大部分都过于晦涩,我觉得可以作为字典查阅,没必要逐条深究。但我认为那些有趣的、有用的位运算技巧,是我们每个人需要掌握的。​
......@@ -126,6 +126,8 @@ while (true) {
// 输出:1,2,3,4,1,2,3,4,1,2,3,4...
```
> note:注意这个技巧只适用于数组长度是 2 的幂次方的情况,比如 2、4、8、16、32 以此类推。至于如何将数组长度扩展为 2 的幂次方,这也是有比较巧妙的位运算算法的,可以参考 https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
简单说,`& (arr.length - 1)` 这个位运算能够替代 `% arr.length` 的模运算,性能会更好一些。
那问题来了,现在是不断地 `index++`,你做到了循环遍历。但如果不断地 `index--`,还能做到环形数组的效果吗?
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册