Skip to content

Instantly share code, notes, and snippets.

@maydayco
maydayco / gist:5711101
Created June 5, 2013 01:55
Binary Tree Maximum Path Sum
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@maydayco
maydayco / gist:5711043
Created June 5, 2013 01:36
Surrounded Regions
public class Solution {
public void solve(char[][] board) {
// Start typing your Java solution below
// DO NOT write main() function
int n = board.length;
if (n == 0)
return;
int m = board[0].length;
for (int i = 0; i < board.length; i++)
@maydayco
maydayco / gist:5708839
Last active December 18, 2015 02:09
Populating Next Right Pointers in Each Node II
/**
* Definition for binary tree with next pointer.
* public class TreeLinkNode {
* int val;
* TreeLinkNode left, right, next;
* TreeLinkNode(int x) { val = x; }
* }
*/
public class Solution {
public void connect(TreeLinkNode root) {
@maydayco
maydayco / gist:5708499
Created June 4, 2013 18:58
Flatten Binary Tree to Linked List
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@maydayco
maydayco / gist:5701654
Last active December 18, 2015 01:09
Convert Sorted List to Binary Search Tree
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode(int x) { val = x; next = null; }
* }
*/
/**
* Definition for binary tree
@maydayco
maydayco / gist:5701079
Created June 3, 2013 20:24
Balanced Binary Tree
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@maydayco
maydayco / gist:5700891
Created June 3, 2013 19:59
Convert Sorted Array to Binary Search Tree
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@maydayco
maydayco / gist:5700856
Created June 3, 2013 19:54
Binary Tree Level Order Traversal II
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@maydayco
maydayco / gist:5700828
Created June 3, 2013 19:51
Construct Binary Tree from Inorder and Postorder Traversal
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@maydayco
maydayco / gist:5700689
Created June 3, 2013 19:32
Construct Binary Tree from Preorder and Inorder Traversal
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {