Solution

package
v0.0.0-...-48c9e09 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: MIT Imports: 1 Imported by: 0

README

1. Two Sum

Problem

Description

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.

An input string is valid if:

Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Note that an empty string is also considered valid.

Example
Input: "()"
Output: true

Input: "()[]{}"
Output: true

Input: "(]"
Output: false

Input: "([)]"
Output: false

Input: "{[]}"
Output: true

Solution

Approach1
Approach2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValid

func IsValid(s string) bool

Types

type Stack

type Stack struct {
	// contains filtered or unexported fields
}

自己写的一个栈,注意interface传递参数的转换

func (*Stack) IsEmpty

func (this *Stack) IsEmpty() bool

func (*Stack) Len

func (this *Stack) Len() int

func (*Stack) Pop

func (this *Stack) Pop() interface{}

func (*Stack) Push

func (this *Stack) Push(x interface{})

func (*Stack) Top

func (this *Stack) Top() interface{}

Jump to

Keyboard shortcuts

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