This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. | |
get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. | |
put(key, value) - Set or insert the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item before inserting a new item. | |
The cache is initialized with a positive capacity. | |
Follow up: | |
Could you do both operations in O(1) time complexity? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. | |
Note: A leaf is a node with no children. | |
Example: | |
Given the below binary tree and sum = 22, | |
5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum. | |
Note: A leaf is a node with no children. | |
Example: | |
Given the below binary tree and sum = 22, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Write a function that takes an unsigned integer and return the number of '1' bits it has (also known as the Hamming weight). | |
Example 1: | |
Input: 00000000000000000000000000001011 | |
Output: 3 | |
Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits.*/ | |
class Solution { | |
public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. | |
An example is the root-to-leaf path 1->2->3 which represents the number 123. | |
Find the total sum of all root-to-leaf numbers. | |
Note: A leaf is a node with no children. | |
Example: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: | |
a binary tree in which the left and right subtrees of every node differ in height by no more than 1. | |
Example 1: | |
Given the following tree [3,9,20,null,null,15,7]: | |
3 | |
/ \ | |
9 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Given a binary tree, find its maximum depth. | |
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. | |
Note: A leaf is a node with no children. | |
Example: | |
Given binary tree [3,9,20,null,null,15,7], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). | |
For example: | |
Given binary tree [3,9,20,null,null,15,7], | |
3 | |
/ \ | |
9 20 | |
/ \ | |
15 7 | |
return its level order traversal as: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). | |
For example, this binary tree [1,2,2,3,4,4,3] is symmetric: | |
1 | |
/ \ | |
2 2 | |
/ \ / \ | |
3 4 4 3 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). | |
For example, this binary tree [1,2,2,3,4,4,3] is symmetric: | |
1 | |
/ \ | |
2 2 | |
/ \ / \ | |
3 4 4 3 | |
NewerOlder