Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Fishicat opened this issue Apr 23, 2020 · 1 comment
Open

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

Fishicat opened this issue Apr 23, 2020 · 1 comment

Comments

@Fishicat
Copy link

输出结果为""

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
@mikeqoo1
Copy link

mikeqoo1 commented Jul 29, 2020

有點像bug...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants