stack

package
v0.0.0-...-eb09a2a Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SimplifyPath

func SimplifyPath(path string) string

解法一

Example
package main

import (
	"fmt"
)

type question71 struct {
	para71
	ans71
}

// para 是参数
// one 代表第一个参数
type para71 struct {
	s string
}

// ans 是答案
// one 代表第一个答案
type ans71 struct {
	one string
}

func main() {

	qs := []question71{

		{
			para71{"/.hidden"},
			ans71{"/.hidden"},
		},

		{
			para71{"/..hidden"},
			ans71{"/..hidden"},
		},

		{
			para71{"/abc/..."},
			ans71{"/abc/..."},
		},

		{
			para71{"/home/"},
			ans71{"/home"},
		},

		{
			para71{"/..."},
			ans71{"/..."},
		},

		{
			para71{"/../"},
			ans71{"/"},
		},

		{
			para71{"/home//foo/"},
			ans71{"/home/foo"},
		},

		{
			para71{"/a/./b/../../c/"},
			ans71{"/c"},
		},
	}

	for _, q := range qs {
		_, p := q.ans71, q.para71
		fmt.Println(p, SimplifyPath(p.s))
	}
}
Output:

{/.hidden} /.hidden
{/..hidden} /..hidden
{/abc/...} /abc/...
{/home/} /home
{/...} /...
{/../} /
{/home//foo/} /home/foo
{/a/./b/../../c/} /c

func SimplifyPath1

func SimplifyPath1(path string) string

解法二 golang 的官方库 API

func ValidParentheses

func ValidParentheses(s string) bool
Example
package main

import (
	"fmt"
)

type question20 struct {
	para20
	ans20
}

// para 是参数
// one 代表第一个参数
type para20 struct {
	one string
}

// ans 是答案
// one 代表第一个答案
type ans20 struct {
	one bool
}

func main() {

	qs := []question20{

		{
			para20{"()[]{}"},
			ans20{true},
		},
		{
			para20{"(]"},
			ans20{false},
		},
		{
			para20{"({[]})"},
			ans20{true},
		},
		{
			para20{"(){[({[]})]}"},
			ans20{true},
		},
		{
			para20{"((([[[{{{"},
			ans20{false},
		},
		{
			para20{"(())]]"},
			ans20{false},
		},
		{
			para20{""},
			ans20{true},
		},
		{
			para20{"["},
			ans20{false},
		},
	}

	for _, q := range qs {
		_, p := q.ans20, q.para20
		fmt.Println(p, ValidParentheses(p.one))
	}

}
Output:

{()[]{}} true
{(]} false
{({[]})} true
{(){[({[]})]}} true
{((([[[{{{} false
{(())]]} false
{} true
{[} false

Types

This section is empty.

Jump to

Keyboard shortcuts

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