## LeetCode – Reconstruct Itinerary (Java)

Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man who departs from JFK. Thus, the itinerary must begin with JFK.

## LeetCode – Self Crossing (Java)

Analysis This problem can be easily solved if the three self crossing cases are summarized well. Here are the three self crossing cases. There are no other self crossing situations based on the restrictions of counter-clockwise. Java Solution Writing the solution is straightforward once the 3 self crossing cases are identified. public boolean isSelfCrossing(int[] x) … Read more

## LeetCode – House Robber III (Java)

The houses form a binary tree. If the root is robbed, its left and right can not be robbed. Analysis Traverse down the tree recursively. We can use an array to keep 2 values: the maximum money when a root is selected and the maximum value when a root if NOT selected. Java Solution public … Read more

## LeetCode – Counting Bits (Java)

Given a non negative integer number num. For every numbers i in the range 0 â‰¤ i â‰¤ num calculate the number of 1’s in their binary representation and return them as an array. Example: For num = 5 you should return [0,1,1,2,1,2]. 1. Naive Solution We can simply count bits for each number like … Read more

## Print an Array in Java

This post summarizes 5 different ways of printing an array in Java.

## System.arraycopy() vs. Arrays.copyOf() in Java

If we want to copy an array, we can use either `System.arraycopy()` or `Arrays.copyOf()`. In this post, I use a simple example to demonstrate the difference between the two.

## LeetCode – Odd Even Linked List (Java)

Problem

Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

## Implement a Stack Using an Array in Java

This post shows how to implement a stack by using an array.

The requirements of the stack are: 1) the stack has a constructor which accepts a number to initialize its size, 2) the stack can hold any type of elements, 3) the stack has a push() and a pop() method.