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 two integers n and k, return all possible combinations of k numbers out of 1 ... n. | |
For example, | |
If n = 4 and k = 2, a solution is: | |
[ | |
[2,4], | |
[3,4], | |
[2,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
/** | |
* Definition for singly-linked list. | |
* public class ListNode { | |
* int val; | |
* ListNode next; | |
* ListNode(int x) { | |
* val = x; | |
* next = null; | |
* } | |
* } |
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
""" | |
Follow up for problem "Populating Next Right Pointers in Each Node". | |
What if the given tree could be any binary tree? Would your previous solution still work? | |
Note: | |
You may only use constant extra space. | |
For example, | |
Given the following binary tree, |
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
/* | |
Follow up for problem "Populating Next Right Pointers in Each Node". | |
What if the given tree could be any binary tree? Would your previous solution still work? | |
Note: | |
You may only use constant extra space. | |
For example, | |
Given the following binary tree, |
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. | |
For example, | |
1 |
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. | |
For example, | |
1 |
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 minimum depth. | |
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. | |
""" | |
# Definition for a binary tree node | |
# class TreeNode: | |
# def __init__(self, x): |
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
class Solution: | |
# @param A, a list of integers | |
# @param target, an integer to be searched | |
# @return an integer | |
def search(self, A, target): | |
if A==None or len(A)==0: | |
return -1; | |
st=0; | |
ed=len(A)-1 | |
return self.searchHelper(A, target, st, ed) |
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 n non-negative integers representing an elevation map where the width of each bar is 1, | |
compute how much water it is able to trap after raining. | |
For example, | |
Given [0,1,0,2,1,0,1,3,2,1,2,1], return 6. | |
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. | |
In this case, 6 units of rain water (blue section) are being trapped. Thanks Marcos for contributing this image! |