## LeetCode – Subsets II (Java)

Given a set of distinct integers, S, return all possible subsets. Note: Elements in a subset must be in non-descending order. The solution set must not contain duplicate subsets. For example, If S = [1,2,3], a solution is: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] Thoughts Comparing this problem with Subsets can … Read more

## LeetCode – Remove Duplicates from Sorted Array (Java)

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. For example, given input array A = [1,1,2], your function should return length = 2, and A … Read more

## LeetCode – Remove Duplicates from Sorted Array II (Java)

Follow up for “Remove Duplicates“: What if duplicates are allowed at most twice? For example, given sorted array A = [1,1,1,2,2,3], your function should return length = 5, and A is now [1,1,2,2,3]. So this problem also requires in-place array manipulation. Java Solution 1 We can not change the given array’s size, so we only … Read more

## Machine Learning Resources

Here are some good machine learning resources. The Unreasonable Effectiveness of Recurrent Neural Networks: http://karpathy.github.io/2015/05/21/rnn-effectiveness/ Stanford deep learning for NLP (lecture notes): https://cs224d.stanford.edu/lecture_notes/ NTU deep learning (lecture notes): http://speech.ee.ntu.edu.tw/~tlkagk/courses_MLDS17.html LSTM Hello World: https://medium.com/towards-data-science/lstm-by-example-using-tensorflow-feb0c1968537 HBOâ€™s Silicon Valley â€œNot Hotdog”: https://medium.com/@timanglade/how-hbos-silicon-valley-built-not-hotdog-with-mobile-tensorflow-keras-react-native-ef03260747f3 Use the TimeDistributed Layer for LSTM: https://machinelearningmastery.com/timedistributed-layer-for-long-short-term-memory-networks-in-python/ Deep learning intro: https://medium.com/machine-learning-for-humans/neural-networks-deep-learning-cdad8aeae49b

## Use K-Nearest Neighbors (KNN) Classifier in Java

Case Study Image you have a blog which contains a lot of nice articles. You put ads at the top of each article and hope to gain some revenue. After a while and from your report, you see that some posts generate revenue and some do not. Assuming that whether an article generates revenue or … Read more

## How to handle noise?

If you apply for a data job, this is a commonly asked interview question. It can show your experience and understanding of machine learning. First of all, noise can occur in both input (X) and output (Y). Missing Values in X 1. Use the features’s mean value from all the available data 2. Ignore the … Read more

## Can Constructor Throw Exceptions in Java?

1. The question In Java, methods can throw exceptions. Can constructors also throw exceptions? The answer is YES. 2. The reason and some necessary background A constructor is just a special method. In this perspective, it surely can do what regular methods can do. It is possible that there are some objects created and assigned … Read more

## LeetCode – Convert Sorted Array to Binary Search Tree (Java)

Given an array where elements are sorted in ascending order, convert it to a height balanced BST. Java Solution A typical DFS problem using recursion. // Definition for binary tree class TreeNode { int val; TreeNode left; TreeNode right;   TreeNode(int x) { val = x; } }   public class Solution { public TreeNode … Read more

## LeetCode – Convert Sorted List to Binary Search Tree (Java)

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST. Thoughts If you are given an array, the problem is quite straightforward. But things get a little more complicated when you have a singly linked list instead of an array. Now you no longer have random … Read more

## LeetCode – Distinct Subsequences Total (Java)

Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (ie, “ACE” is … Read more

## Remove WP-Syntax Alternative Line Background Color

Recently, when I upgrade wp-syntax plugin, it shows code in alternative background color for each line. This is so annoying and makes the code not readable. It looks like the following: The solution is simple. Go to Edit the plugin, and select the wp-syntax/css/wp-syntax.css to edit. First comment out the following code by using “/* … Read more

## Sort LinkedList of User-Defined Objects in Java

For sorting a list in Java, you can use sort(List<T> list) method. This method can sort a list in which all elements must implement the Comparable interface. In the example below, the House class is user-defined. To make it comparable, it implements the Comparable interface. By using the sort(List<T> list) method, it can be sorted … Read more

## What is Machine Learning?

Machine learning: A takes D and H to get g. A: learning algorithm D: training data set H: all possible hypothesis g: learned hypothesis It can be shown in the following diagram:

## A Simple Machine Learning Example in Java

This is a “Hello World” example of machine learning in Java. It simply give you a taste of machine learning in Java. Environment Java 1.6+ and Eclipse Step 1: Download Weka library Download page: http://www.cs.waikato.ac.nz/ml/weka/snapshots/weka_snapshots.html Download stable.XX.zip, unzip the file, add weka.jar to your library path of Java project in Eclipse. Step 2: Prepare Data … Read more

## LeetCode – Subsets (Java)

Given a set of distinct integers, S, return all possible subsets. Note: 1) Elements in a subset must be in non-descending order. 2) The solution set must not contain duplicate subsets. For example, given S = [1,2,3], the method returns: [ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ] Thoughts Given a set S … Read more