Git Product home page Git Product logo

leetcodeutil's Introduction

Tools for leetcode

This package contains useful implementations of data structurs used in leetcode.

Install

> go get github.com/yskang/leetCodeUtil/leetData

treeNode

A treeNode has a one integer value and two pointers which point other treeNode.

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

In leetcode problems, the initial value of this structure is provided by a string like this.

[3,9,20,null,null,15,7]

It is very hard to create test of my own input. So, I make this utils to creating custom testing set easliy.

With this package, you can make TreeNode using a same formatted string in the problem, compare two TreeNode structures, and print TreeNode as a string.

How to use

Using MakeTreeNode function in this package, you can make new treeNode with a initial string.

tree = MakeTreeNode("1,null,2,3,null,4,5")

The package has compare and print function. So, you can make a unit test for problems which use treeNode.

treeA := MakeTreeNode("1,2,3,4,5")
treeB := MakeTreeNode("1,2,3,4,5")
treeC := MakeTreeNode("1,2,3,4,null,5")
fmt.Println(CompareTreeNode(treeA, treeB))
fmt.Println(CompareTreeNode(treeA, treeC))

// output:
// true
// false

tree = MakeTreeNode("1,null,2,3,null,4,5")
fmt.Println(tree)

// output: 
// 1,null,2,3,null,4,5

listNode

A listNode has a one integer value and one pointer which point other listNode.

type ListNode struct {
	Val  int
	Next *ListNode
}

You can make a listNode using a list of integers and print as a string.

How to use

Create a listNode with a list of integers.

InitListNode([]int{1, 2, 3, 4, 5}

InitListNode returns a pointer of created listNode.

You can print a listNode as a string.

fmt.Println(InitListNode([]int{1, 2, 3, 4, 5}))
// output:
// 1,2,3,4,5

leetcodeutil's People

Contributors

yskang avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.