123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package main
- import (
- "fmt"
- "os"
- "sort"
- )
- func main(){
- PathCheck("D:/11")
- }
- func PathCheck(path string){
- b,err :=PathExists(path)
- if err != nil {
- fmt.Println("exist err",err)
- }
- if !b{
- fmt.Println("不存在目录,重新创建")
- err = os.Mkdir("D:/11/", 0777)
- if err != nil {
- fmt.Println("Mkdir err",err)
- }
- }
- }
- func PathExists(path string) (bool, error) {
- _, err := os.Stat(path)
- if err == nil {
- return true, nil
- }
- if os.IsNotExist(err) {
- return false, nil
- }
- return false, err
- }
- func groupAnagrams(strs []string) [][]string {
- res := [][]string{}
- m := make(map[string][]string)
- for _, str := range strs {
- tem := []byte(str)
- sortstring(tem)
- m[string(tem)] = append(m[string(tem)],str)
- }
- for _, va := range m {
- res = append(res,va)
- }
- return res
- }
- func sortstring(s []byte){
- sort.Slice(s, func(i, j int) bool {
- return s[i]<s[j]
- })
- }
|