I faced a problem when I try to add List to List< List > in java, and it did consume some my time. It is a common problem and I even can remember I got stuck on debugging because of this "feature" at least twice. To let me remember this problem and avoid making it …
When I try to add List to List
Building a functional chat app based on Node.js (2)
Web Sockets Web Sockets are a much more responsive technology, since they keep a connection directly open at all times for each client. This allows either the client or server to directly notify each other when changes occur on their side. In contrast to the request / response model, the server does not wait for …
Continue reading “Building a functional chat app based on Node.js (2)”
Building a functional chat app based on Node.js (1)
Introduction We’ll use our new NodeJS knowledge to build a realistic web server that handles the backend of a messaging app for realtime chatting. We will also create a minimal front end so we can see the service working. These skills will be very applicable to those of you who are creating a web app …
Continue reading “Building a functional chat app based on Node.js (1)”
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 …