Skip to content

Instantly share code, notes, and snippets.

// solves https://leetcode.com/problems/remove-linked-list-elements/description/
// runtime is 19ms
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
// solves https://leetcode.com/problems/remove-linked-list-elements/description/
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
@scriptnull
scriptnull / binary_postorder_traversal_iterative.java
Created November 2, 2017 07:53
Binary Tree Postorder traversal
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
@scriptnull
scriptnull / two_three_tree.cr
Created October 29, 2017 18:44
A simple example of crystal code using tagged unions to create a 2 3 tree
class TwoNode(T)
@data : T
@left : Nil | TwoNode(T) | ThreeNode(T)
@right : Nil | TwoNode(T) | ThreeNode(T)
def initialize(@data, @left, @right)
end
end
class ThreeNode(T)
@scriptnull
scriptnull / binary_postorder_traversal_recursive.go
Created October 29, 2017 11:23
Binary tree post order traversal recursive approach.
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func postorderTraversal(root *TreeNode) []int {
var result []int
@scriptnull
scriptnull / binary_inorder_traversal_morris.java
Last active October 29, 2017 11:05
Binary Tree inorder traversal iterative approach, without using stacks and using morris traversal.
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func inorderTraversal(root *TreeNode) []int {
var result []int
@scriptnull
scriptnull / binary_inorder_traversal_iterative.java
Created October 29, 2017 07:59
Binary tree inorder traversal using a iterative approach with help of a stack.
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
@scriptnull
scriptnull / binary_inorder_traversal_recursive.go
Created October 28, 2017 12:26
Inorder Traversal in binary tree.
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func inorderTraversal(root *TreeNode) []int {
var result []int
@scriptnull
scriptnull / binary_preorder_traversal_iterative.java
Created October 28, 2017 12:03
Pre order Traversal in binary tree using an iterative approach.
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
@scriptnull
scriptnull / binary_preorder_traversal_recursive.go
Created October 28, 2017 11:21
Pre order Traversal in binary tree
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func preorderTraversal(root *TreeNode) []int {
var result []int