Solution for problems on www.lintcode.com