Skip to content

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

Description

@consoles
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;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions