Menu Sidebar
Menu

LintCode

[LintCode] Update Bits

n = n & ~(1 << k); 就是把n中的第k个bit设为0 n = n | ((m & (1<<(k-i)))<<i); m & (1<<(k-i)) 是从m的第一个bit开始扫描.因为已知j-i = size of (m)2 ((m & (1<<(k-i)))<<i) 扫描后, 往左shift i位对准n上的i位. n = n | ((m & (1<<(k-i)))<<i) 把n的第i位到j位设为m的0~(j-i)位

Recover Rotated Sorted Array

 

Partition Array by Odd and Even

给一个数组, 把奇数放左边, 偶数放右边. 其实就是一个quicksort的partition的改写, 改写的地方很少, 就是判断条件从 nums[i] 对 nums[k]的比较改成nums[i] % 2 != 0的比较.

 

Binary Tree Paths

打印所有的从root到leaf的path. 开始用的queue做的..后来看了下别的人的答案, 感觉都很简练.po一个别人的答案  

 

[LintCode] Copy Books

[LintCode] Longest Increasing Continuous subsequence II

 

[LintCode] Longest Increasing Continuous subsequence

 

[LintCode] Count and Say

[LintCode] Segment Tree Query II

[LintCode] Segment Tree Query

Older Posts

书脊

倾城与倾国, 佳人难再得