Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public boolean backspaceCompare(String s, String t) {
- Stack <Character> stacks = new Stack<>();
- Stack <Character> stackT = new Stack<>();
- for(Character ss:s.toCharArray()){
- if(ss!='#'){
- stacks.push(ss);
- }else if (!stacks.isEmpty()){
- stacks.pop();
- }
- }
- for(Character tt:t.toCharArray()){
- if(tt!='#'){
- stackT.push(tt);
- }else if (!stackT.isEmpty()){
- stackT.pop();
- }
- }
- return stacks.equals(stackT) ;
- }
- }
- //Input: s = "ab#c", t = "ad#c"
- //Output: true
- //Explanation: Both s and t become "ac".
- //# deletes letter = backspace
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement