Quantcast
Channel: March 2015 – Program Creek
Browsing all 6 articles
Browse latest View live

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. 1. Simple Code Examples...

View Article


Print an Array in Java

This post summarizes 5 different ways of printing an array in Java. 5 Different Ways of Printing an Array Arrays.toString(arr) for(int n: arr) System.out.println(n+", "); for (int i = 0; i <...

View Article

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...

View Article

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...

View Article

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...

View Article


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...

View Article
Browsing all 6 articles
Browse latest View live