Contains Duplicate II

Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and j is at most k. My solution (solution 1) is the most elementary method to deal with problem like this, but…

Valid Sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles – The Rules. The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’. Note: A valid Sudoku board (partially filled) is not necessarily solvable. Only the filled cells need to be validated. The rule of Sudoku: 1. Each row…

Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins.  Notes: If the two linked lists have no intersection at all, return null. The linked lists must retain their original structure after the function returns. You may assume there are no cycles anywhere in the entire linked structure….

Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.


It has been a week since I started practicing coding. Time seems to go slowly when I deal with tough things.. but I will try to be the best myself and keep up with it 🙂 

Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space.

Balanced Binary Tree

Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.    Solution 2: a faster method (ref: 九章算法)

House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the…

Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). Comments: we should solve this problem recursively, which means we need to discuss the basic cases first. 

Power of Two

Given an integer, write a function to determine if it is a power of two. Comments: the number that is the power of 2 has only the first digit as 1 in its binary form.