leetcode

package module
v0.0.0-...-d092094 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 0 Imported by: 0

README

leetcode

Leetcode problem solution in Go programming

1. Two sum problem
The two sum problem is a common interview question, and it is a variation of the subset sum problem. There is a popular dynamic programming solution for the subset sum problem, but for the two sum problem we can actually write an algorithm that runs in O(n) time. The challenge is to find all the pairs of two integers in an unsorted array that sum up to a given S.
For example, if the array is [3, 5, 2, -4, 8, 11] and the sum is 7, your program should return [[11, -4], [2, 5]] because 11 + -4 = 7 and 2 + 5 = 7.
2. Add Two Numbers
  You may assume the two numbers do not contain any leading zero, except the number 0 itself.
  
  Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
  Output: 7 -> 0 -> 8

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TwoSum

func TwoSum(arr []int, s int) [][]int

The two sum problem is a common interview question, and it is a variation of the subset sum problem. There is a popular dynamic programming solution for the subset sum problem, but for the two sum problem we can actually write an algorithm that runs in O(n) time. The challenge is to find all the pairs of two integers in an unsorted array that sum up to a given S.

func TwoSum1

func TwoSum1(nums []int, target int) [][]int

Types

type ListNodes

type ListNodes struct {
	Head *Node
}

ListNodes is very good field

func (*ListNodes) AddToHead

func (ll *ListNodes) AddToHead(data int)

type Node

type Node struct {
	Val  int
	Next *Node
}

Node element

func AddTwoNumbers

func AddTwoNumbers(l1 *Node, l2 *Node) *Node

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL