随笔分类 - Algorithms
摘要:// --- Directions // Given a string, return the character that is most // commonly used in the string. // --- Examples // maxChar("abcccccccd") === "c" // maxChar("apple 1231111") === "1" function m...
阅读全文
摘要:How to calculate the area of polygon. For a triangle like: We can calculate the area: This approach is able to solve all simple polygon areas problem:
阅读全文
只有注册用户登录后才能阅读该文。
摘要:12's factors are: {1,2,3,4,6,12}
阅读全文
摘要:Given a number N, the output should be the all the prime numbers which is less than N. The solution is called Sieve of Eratosthenes: First of all, we
阅读全文
只有注册用户登录后才能阅读该文。
摘要:125, how to conver to binary number?
阅读全文
只有注册用户登录后才能阅读该文。
摘要:Asking you to implement the Math.pow method The navie implemenation can be: It takes O(N) time. Now if we want to improve it to O(logN) time. we can d
阅读全文
摘要:For Fibonacci Sequence, the space complexity should be the O(logN), which is the height of tree. Check the source
阅读全文
摘要:function Node(val) { return { val, left: null, right: null }; } function Tree() { return { root: null, addLeft(val, root) { const newNode = Node(val); root.lef...
阅读全文
摘要:Given a string, find the length of the longest substring without repeating characters. Example 1: Input: "abcabcbb" Output: 3 Explanation: The answer
阅读全文
摘要:You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way. The null node needs to be rep
阅读全文
摘要:Assume we have two linked list, we want to find a point in each list, from which all the the nodes share the same value in both list. Then we call thi
阅读全文
摘要:For the given tree, in order traverse is: visit left side root visit right side The successor is the one right next to the target: So, given the tree
阅读全文
摘要:The solution for the problem can be divided into three cases: case 1: if the delete node is leaf node, then we can simply remove it case 2: if the del
阅读全文
摘要:What is Binary Search Tree (BST) A binary tree in which for each node, value of all the nodes in left subtree is less or equal and value of all the no
阅读全文
摘要:Algorithm or program to check for balanced parentheses in an expression using stack data structure. For example: The idea to solve the problem is: ope
阅读全文
摘要:The idea to solve the problem is set five variable, first direction, we need to switch direction after we finish printing one row or one column. Then
阅读全文
摘要:Give you set of meetings start time and end time, count how many meeting rooms needed. For example: We can use a memo table to store the at which time
阅读全文