Golang-Interview icon indicating copy to clipboard operation
Golang-Interview copied to clipboard

193题答案和个人思路(望大家指点)

Open Fishicat opened this issue 4 years ago • 1 comments

输出结果为""

strings.TrimRight的作用是把有包含第二个参数的组合项的对应字母都替换掉,比如"BA"的组合集合为{"BA", "AB", "A", "B"}; 但是它有一个中止条件,如果从右到左有一个字母或字母组合不为"BA"的排列组合集合中的元素,便会停止cut,把当前已cut完的字符串返回 测试代码如下:

import (
        "fmt"
        "strings"
)

func main() {
        var f = func(example, cutset string) {
		result := strings.TrimRight(example, cutset)
		fmt.Println(result == "")
		fmt.Printf("example : %s, cutset : %s, result : %s\n", example, cutset, result)
	}

	f("ABBA", "BA")
	f("ABCBA", "BA")
}
###############################
Output:
true
example : ABBA, cutset : BA, result : 
false
example : ABCBA, cutset : BA, result : ABC

Fishicat avatar Apr 23 '20 06:04 Fishicat

  • https://blog.cyeam.com/golang/2015/08/19/trim

有點像bug...

mikeqoo1 avatar Jul 29 '20 07:07 mikeqoo1