https://www.xavignu.com/?p=1771
LeetCode problem 167