> For the complete documentation index, see [llms.txt](https://hannahpun.gitbook.io/leetcode-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hannahpun.gitbook.io/leetcode-note/stack/bf-165.-remove-characters.md).

# BF 165. remove characters

通常刪字的都是 Stack

[bigfrontend](https://bigfrontend.dev/problem/remove-characters)

```
Given a string contaning only a, b and c, remove all b and ac.

removeChars('ab') // 'a'
removeChars('abc') // ''
removeChars('cabbaabcca') // 'caa'
```

````
```javascript
/**
 * @param {string} input
 * @returns string
 */
function removeChars(input) {
   let stack = []
   for(let i = input.length-1; i>=0; i--){
    if(input[i] === "a" && stack[0] === "c"){
      stack.shift()
      
    } else if(input[i] !== "b"){
      stack.unshift(input[i])
    }
  }

  return stack.join("")
}

```
````

### 怎麼解?

先把需要用蛋目前未用的 "c" 存進 stack
