Skip to content

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

@consoles

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

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