945 words 1 mins.

1254 · Sum of Left Leaves - LintCode # Description Find the sum of all left leaves in a given binary tree. Example Example 1 Input: {3,9,20,#,#,15,7} Output:24 Explanation:There are two left leaves in the binary tree, with values 9 and 15 respectively. Return 24. 3 / \ 9 20 /...
3.5k words 3 mins.

1883 · Top K Frequently Mentioned Keywords - LintCode # Description Given a list of reviews, a list of keywords and an integer k . Find out the top k keywords that appear most frequently in different comments, and the K keywords are sorted according to the number of times. The comparison of strings...
978 words 1 mins.

920 · Meeting Rooms - LintCode # Description Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings. (0,8),(8,10) is not conflict at 8 # Example Example1 Input: intervals =...
1.7k words 2 mins.

134 · LRU Cache - LintCode # Description Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set . get(key) Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. set(key,...
1.1k words 1 mins.

423 · Valid Parentheses - LintCode # Description Given a string containing just the characters '(', ')' , '{' , '}' , '[' and ']' , determine if the input string is valid. The brackets must close in the correct order,...
1.1k words 1 mins.

1181 · Diameter of Binary Tree - LintCode # Description Given a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. # Example Example 1: Given a binary tree 1 / \ 2 3 / \ 4 5 Return...
1.1k words 1 mins.

53 · Reverse Words in a String - LintCode # Description Given an input string, reverse the string word by word. What constitutes a word? A sequence of non-space characters constitutes a word and some words have punctuation at the end. Could the input string contain leading or trailing spaces? Yes....
1.3k words 1 mins.

158 · Valid Anagram - LintCode # Description Write a method anagram(s,t) to decide if two strings are anagrams or not. What is Anagram? Two strings are anagram if they can be the same after change the order of characters. # Example Example 1: Input: s = "ab", t =...
1.3k words 1 mins.

68 · Binary Tree Postorder Traversal - LintCode # Description Given a binary tree, return the postorder traversal of its nodes’ values. The first data is the root node, followed by the value of the left and right son nodes, and "#" indicates that there is no child node. The...