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

第二题中的一些疑问? #8

Open
gq-tang opened this issue Mar 20, 2019 · 4 comments
Open

第二题中的一些疑问? #8

gq-tang opened this issue Mar 20, 2019 · 4 comments

Comments

@gq-tang
Copy link

gq-tang commented Mar 20, 2019

既然都是ASCII码,那长度大于256必定会出现重复的,所以改为以下是不是可以:

func isUniqueString(s string) bool {
	if len(s) > 256 {
		return false
	}

	unique := make(map[int32]bool)

	for _, v := range s {
		if v > 256 {
			return false
		}
		if _, ok := unique[v]; ok {
			return false
		} else {
			unique[v] = true
		}
	}
	return true
}
@lifei6671
Copy link
Owner

不允许使用其他数据结构。你这里使用了map。

@gq-tang
Copy link
Author

gq-tang commented Mar 20, 2019

哦,那改成这样可以吧?

func isUniqueString(s string) bool {
	if len(s) > 256 {
		return false
	}

	for _, v := range s {
		if v > 256 {
			return false
		}
		if strings.Count(s, string(v)) > 1 {
			return false
		}
	}
	return true
}

@lifei6671
Copy link
Owner

只有127个可以在键盘上打出来的,所以不用判断127之后的。

@NightmareZero
Copy link

NightmareZero commented Nov 23, 2021

只有127个可以在键盘上打出来的,所以不用判断127之后的。

只要大于127,就必然重复这个事肯定的,不过和键盘没关系,ASCII码表长度就128,不过你那个题目有点坑

保证字符串中的字符为【ASCII字符】。字符串的长度小于等于【3000】。 这句话到底是题目保证的还是要实现的啊

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

3 participants