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

问题3,最长公共不重复字符串貌似有更简单的解法 #2

Open
consoles opened this issue Feb 1, 2018 · 1 comment
Open

Comments

@consoles
Copy link

consoles commented Feb 1, 2018

function solve(str) {
	var maxStr = '',
	    tmpStr = '';

	var hashed = {};
	for (const c of str) {
		if (!hashed[c]) {
			hashed[c] = true;
			tmpStr += c;
		} else {
			if (tmpStr.length > maxStr.length) {
				maxStr = tmpStr;
				tmpStr = c;
			}
		}
	}

	return maxStr;
}
@ecmadao
Copy link
Owner

ecmadao commented Feb 1, 2018

@consoles
感谢指明!
每道题都应该会有其最优的解法,因为毕竟很多题我只写出了自己第一时间想到的方法。。而且随着题目序数的增大,我的题解应该会有所进步吧,毕竟自己是按照顺序从第一题开始刷的。。🌚

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