标签:左右 .com 返回 判断字符串 ring 技术 else microsoft push
一、思路
二、代码
function is_leagl_brackets(string) { var array = []; for (var i = 0; i < string.length; i++) { var item = string[i]; if (item === "(") { array.push("("); } else if (item === ")") { if (array.length === 0) { return false; } else { array.pop(); } } else { continue; } }; return array.length === 0; }; console.log("(asd):", is_leagl_brackets("(asd)")); console.log("asd(asd(adsfsdf(asdf())))):", is_leagl_brackets("asd(asd(adsfsdf(asdf()))))"));
三、查看结果
标签:左右 .com 返回 判断字符串 ring 技术 else microsoft push
原文地址:https://www.cnblogs.com/hcxwd/p/10420835.html