1.6k words 1 mins.

"private static" and "private" methods are added to interface in Java 9. Now private methods can be implemented "static" or "non-static". Here's the example using default method to access the private non-static...
1.1k words 1 mins.

891 · Valid Palindrome II - LintCode # Description Given a non-empty string  s , you may delete at most one character. Judge whether you can make it a palindrome.) The string will only contain lowercase characters. The maximum length of the string is 50000. # Example Example 1: Input: s =...
844 words 1 mins.

124 · Longest Consecutive Sequence - LintCode # Description Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. # Example Input: nums = [100,4,200,1,3,2] Output: 4 Explanation: The longest...
1k words 1 mins.

547 · Intersection of Two Arrays - LintCode # Description Given two arrays, write a function to compute their intersection. Each element in the result must be unique. # Example Example 1: Input: nums1 = [1, 2, 2, 1], nums2 = [2, 2], Output: [2]. Example 2: Input: nums1 = [1, 2], nums2 =...
811 words 1 mins.

689 · Two Sum IV - Input is a BST - LintCode # Description Given a binary search tree and a number  n , find two numbers in the tree that sums equal to  n . Return null if solution cannot be found. # Example 样例 1 输入: {4,2,5,1,3} 3 输出: [1,2] (or [2,1]) 解释: 二叉搜索树如下: 4 / \ 2 5 / \ 1...
4.5k words 4 mins.

Define Single ton class in Java when you make a constructor of a class private, that particular class can generate only one object. This type of class is known as singleton class. # Singleton 單例設計模式 整個類裡只能有一個實例可以被獲取或使用。 e.g. 代表 JVM 運行環境的 Runtime class # 要點 一個類只能有一個實例(instance) 可以 make it to...
1.4k words 1 mins.

380 · Intersection of Two Linked Lists - LintCode # Description Write a program to find the node at which the intersection of two singly linked lists begins. If the two linked lists have no intersection at all, return null . The linked lists must retain their original structure after the function...
827 words 1 mins.

141 · Sqrt(x) - LintCode # Description Implement int sqrt(int x) . Compute and return the square root of x. # Example Example 1: Input: 0 Output: 0 Example 2: Input: 3 Output: 1 Explanation: return the largest integer y that y*y <= x. Example 3: Input: 4 Output: 2 #...
1.1k words 1 mins.

78 · Longest Common Prefix - LintCode # Description Given k strings, find the longest common prefix (LCP). # Example Example 1: Input: K strings = ["ABCD", "ABEF", "ACEF"] Output: "A" Explanation: The longest common prefix is...
919 words 1 mins.

12 · Min Stack - LintCode # Description Implement a stack with following functions: push(val) push val into the stack pop() pop the top element and return it min() return the smallest number in the stack All above should be in O(1) cost min() will never be called when there is no number in the...