寻找字符串里边的最长连续子串

function foo(str){
	if(str == null)return ""
	var curr = ""
	var map = {}
	var count = 0
	//整理map-count
	for(let i in str){
		curr = i
		if(curr[i+1] == curr){
			count ++
		}else{
			map[curr] = 1
		}
	}
	//在map中找出最大的count即target
	var target
	for(let i in map){
		target = map[i]>target?map[i]:target
	}
	//根据target拼接字符串
	var res = ""
	for(let i = 0;i<map[target];i++){
		res+=target
	}
	return res
}

你可能感兴趣的:(js,frontend笔记,面试)