From 1d785da008b0e45462d6e6c7ae4978cfe627964b Mon Sep 17 00:00:00 2001 From: li_chx Date: Mon, 30 Mar 2026 08:40:34 +0800 Subject: [PATCH] =?UTF-8?q?2840.=20=E5=88=A4=E6=96=AD=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E8=83=BD=E5=90=A6=E8=AE=A9=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2=E7=9B=B8=E7=AD=89=20II?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 119 +++++++++++++++++++------------------------------------- 1 file changed, 39 insertions(+), 80 deletions(-) diff --git a/main.go b/main.go index 94d2588..9785f92 100644 --- a/main.go +++ b/main.go @@ -1,91 +1,50 @@ package main -import ( - "fmt" - "strconv" - "strings" -) +import "fmt" -//type Test interface { -//} -// -//func condTest(cond *sync.Cond) { -// cond.L.Lock() -// cond.Wait() -// fmt.Println("condTest") -// cond.L.Unlock() -//} -//func chanTest(ch chan<- *Test) { -// -//} - -func reverse(x int) int { - neg := false - if x < 0 { - neg = true - x = -x - } - s := fmt.Sprintf("%d", x) - var sb strings.Builder - for i := len(s) - 1; i >= 0; i-- { - sb.WriteByte(s[i]) - } - s = sb.String() - var ans int32 = 0 - for c := range s { - t, _ := strconv.ParseUint(string(s[c]), 10, 16) - ans = ans*10 + int32(t) - } - if neg { - ans = -ans - x = -x - } - s1, s2 := fmt.Sprintf("%d", x), fmt.Sprintf("%d", ans) - if neg { - s1 = s1[1:] - s2 = s2[1:] - } - if len(s1) != len(s2) { - for len(s2) < len(s1) { - s2 = "0" + s2 +func isMapEqual(a map[uint8]int, b map[uint8]int) bool { + for k, v := range a { + if val, ok := b[k]; ok { + if val != v { + return false + } + } else { + return false } } - for i := 0; i < len(s1); i++ { - if s1[i] != s2[len(s2)-1-i] { - return 0 + for k, v := range b { + if val, ok := a[k]; ok { + if val != v { + return false + } + } else { + return false } } - return int(ans) + return true +} +func checkStrings(s1 string, s2 string) bool { + mp1 := make(map[uint8]int) + mp2 := make(map[uint8]int) + for i := 0; i < len(s1); i += 2 { + mp1[s1[i]]++ + mp2[s2[i]]++ + } + if !isMapEqual(mp1, mp2) { + return false + } + mp1 = make(map[uint8]int) + mp2 = make(map[uint8]int) + for i := 1; i < len(s1); i += 2 { + mp1[s1[i]]++ + mp2[s2[i]]++ + } + if !isMapEqual(mp1, mp2) { + return false + } + return true } - -//9646324351 -//2147483648 func main() { - fmt.Println(reverse(1534236469)) - //var x int = 16 - //var y any = x - //if _, ok := y.(int); ok { - // fmt.Println(x) - //} - //if _, ok := y.(int32); ok { - // fmt.Println(x) - //} - //var mu sync.Mutex - //sync.NewCond(&mu) - //make(chan *Test, 6) - //var wg sync.WaitGroup - //wg.Add(1) - //wg.Done() - //var mu sync.Mutex - //cond := sync.NewCond(&mu) - // - //go condTest(cond) - //go condTest(cond) - // - //time.Sleep(time.Second * 2) - //cond.L.Lock() - //cond.Broadcast() - //cond.L.Unlock() - //time.Sleep(time.Second * 2) + fmt.Printf("%v", checkStrings("abcdba", "cabdab")) }