Course Schedule II

This is No.210 in LeetCode. I can’t solve this problem by self, but I found a real solid solution and explanation. This is our "main" function: public int[] findOrder(int numCourses, int[][] prerequisites) { int[] incLinkCounts = new int[numCourses]; // incoming edges List<List<Integer>> adjs = new ArrayList<>(numCourses); initialiseGraph(incLinkCounts, adjs, prerequisites); //return solveByBFS(incLinkCounts, adjs); return solveByDFS(adjs); } …

Perfect Squares

This in No.279 in LeetCode. The math theory is: dp[0] = 0 dp[1] = dp[0]+1 = 1 dp[2] = dp[1]+1 = 2 dp[3] = dp[2]+1 = 3 dp[4] = Min{ dp[4-1*1]+1, dp[4-2*2]+1 } = Min{ dp[3]+1, dp[0]+1 } = 1 dp[5] = Min{ dp[5-1*1]+1, dp[5-2*2]+1 } = Min{ dp[4]+1, dp[1]+1 } = 2 . . …

Number of Islands

This is No.200 in LeetCode. The solution is below: public class Solution { private int y; private int x; public int numIslands(char[][] grid) { int res = 0; y = grid.length; if (y == 0) return 0; x = grid[0].length; for (int i = 0; i < y; i++){ for (int j = 0; j …

Circular Array Loop

This is No.457 in LeetCode. The solution is post below: public class Solution { public boolean circularArrayLoop(int[] nums) { if (nums == null || nums.length < 2) return false; int n = nums.length; for (int i = 0; i < n; i++) { if (nums[i] == 0) { continue; } // slow/fast pointer int j …

How to download videos from Youtube?

Download youtube-dl and ffmpeg brew install youtube-dl brew install ffmpeg Re-direct to your video directory cd your_video_dir Download video youtube-dl https://www.youtube.com/watch?v=??? or youtube-dl https://www.youtube.com/watch?v=??? -f mp4 Insert subtitle get subtitle youtube-dl https://www.youtube.com/watch?v=Qkf4farak1k –list-subs download youtube-dl https://www.youtube.com/watch?v=??? –write-sub –embed-sub –sub-lang zh-CN -f mp4 Others Check website youtube-dl \–list-extractors Update youtube-dl -U Help youtube-dl -h

List in Java

List Interface in Java with Examples The List interface provides a way to store the ordered collection. It is a child interface of Collection. It is an ordered collection of objects in which duplicate values can be stored. Since List preserves the insertion order, it allows positional access and insertion of elements. List<Integer> l1 = …

Arrays in Java

Arrays An array is a group of like-typed variables that are referred to by a common name.Arrays in Java work differently than they do in C/C++. Following are some important point about Java arrays. In Java all arrays are dynamically allocated.(discussed below) Since arrays are objects in Java, we can find their length using member …