We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
16. 最接近的三数之和
227. 基本计算器 II
给定一个只包含大写字母的字符串s,字符消除过程是如下进行的: 1)如果s包含长度为2的由相同字母组成的子串,那么这些子串会被消除, 余下的子串拼成新的字符串。例如”ABCCBCCCAA”中”CC”,”CC”和”AA”会被同时消除,余下”AB”, “C”和”B”拼成新的字符串”ABBC”。 2)上述消除会反复一轮一轮进行,直到新的字符串不包含相邻的相同字符为止。 例如”ABCCBCCCAA”经过一轮消除得到”ABBC”,再经过一轮消除得到”AC” 输入描述: 输入包括一行, 由大写字母组成的字符串s,长度不超过100. 输出描述: 对于每组测试数据, 若最后可以把整个字符串全部消除, 就输出 Yes, 否则输出 No. 示例: 输入:ABCCBA 输出:Yes 输入:ABCCCCCBBBBB 输出:No
The text was updated successfully, but these errors were encountered:
//第1题 const threeCountClosest = (nums,target)=>{ let len = nums.length; let res = Number.MAX_SAFE_INTEGER; nums.sort((a,b)=>a-b); for(let i=0;i<len;i++){ let left = i+1; let right = len-1; while(left<right){ let sum = nums[i]+nums[left]+nums[right]; if(Math.abs(sum - target) < Math.abs(res - target)){ res = sum; } if(sum>target){ right--; }else if(sum<target){ left++; }else{ return sum; } } } return res; } //第2题 const calculate = function(s) { const numStack = []; let opt ='+'; let num = 0; for(let i=0;i<=s.length;i++){ const char = s[i]; if(char === ' ') continue; if(parseInt(char)<=9 && parseInt(char)>=0){ num=num*10+parseInt(char); continue; } switch(opt){ case '+':numStack.push(num);break; case '-':numStack.push(-num);break; case '*':numStack.push(numStack.pop()*num);break; case '/':numStack.push(~~(numStack.pop()/num));break; } opt = char; num=0; } return numStack.reduce((pre,cur)=>pre+cur,0); }; //第3题 const isValid = (str)=>{ const stack = []; for(let i =0;i<str.length;i++){ const top = stack.length>0 && stack[stack.length - 1]; if(top === str[i]){ stack.pop(); }else{ stack.push(str[i]); } } return stack.length===0?'Yes':'No'; }
Sorry, something went wrong.
No branches or pull requests
一面笔试题
16. 最接近的三数之和
二面笔试题
227. 基本计算器 II
三面笔试题
The text was updated successfully, but these errors were encountered: