回文检查器(利用双端队列)
function palindromeChecker(aString){ if(aString === undefined || aString ===null || (aString !==null && aString.length === 0)){ return false } const deque = new Deque(); //双端队列 const lowerString = aString.toLowerCase().split(' ').join('') let isEqual = true; let firstChar,lastChar; for(let i=0;i<lowerString.length;i++){ deque.addBack(lowerString,charAt(i)); } while(deque.size()>1 && isEqual){ firstChar = deque.romoveFront(); lastChar = deque.romoveBack(); if(firstChar !== lastChar){ isEqual = false; } } return isEqual }
栈和队列算法 文章被收录于专栏
栈和队列算法