Quantcast
Channel: January 2015 – Program Creek
Browsing latest articles
Browse All 6 View Live

LeetCode – Verify Preorder Serialization of a Binary Tree (Java)

One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node’s value. If it is a null node, we record using a sentinel value such as #. 9 / \...

View Article


How to determine if a string is English or Java code?

Consider the following two strings: 1. for (int i = 0; i < b.size(); i++) { 2. do something in English (not necessary to be a sentence). The first one is Java code, the second one is English. How to...

View Article

LeetCode – Find Median from Data Stream (Java)

Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value. Analysis First of all, it seems that...

View Article

LeetCode – Number of Islands II (Java)

A 2d grid map of m rows and n columns is initially filled with water. We may perform an addLand operation which turns the water at position (row, col) into a land. Given a list of positions to operate,...

View Article

Java Remove Element from ArrayList

To remove some elements from an ArrayList while iterating over the ArrayList, we need to use Iterator. Integer[] arr = {1,2,3,4,5,6}; ArrayList list = new ArrayList(Arrays.asList(arr));...

View Article


LeetCode – Patching Array (Java)

Given a sorted positive integer array nums and an integer n, add/patch elements to the array such that any number in range [1, n] inclusive can be formed by the sum of some elements in the array....

View Article
Browsing latest articles
Browse All 6 View Live