用栈结构实现回文数的判断(JavaScript)
作者:互联网
封装的方法栈方法:
https://www.cnblogs.com/LIXI-/p/16612874.html
判断回文数:
function isHuiwen(str) { let stack = new Stack(); for (let i = 0; i < str.length; i++) { stack.push(str[i]) } let newstr = "" while(!stack.isEmpty()){ newstr += stack.pop() } return str == newstr } console.log(isHuiwen("abcba"));
打印:
true
标签:JavaScript,stack,用栈,let,str,isHuiwen,newstr,回文 来源: https://www.cnblogs.com/LIXI-/p/16615130.html