Question: Write a function called backspaceCompare that takes two strings si and s2 and evaluate them when both are typed into empty text editors. (# means
Write a function called backspaceCompare that takes two strings si and s2 and evaluate them when both are typed into empty text editors. (# means a backspace character). backspaceCompare should return true if the evaluated strings are equal or false if they are not equal. You should make use of the built-in java implementation of the stack data structure under java.util.Stack. (assume that the user inputs correct strings). Example 1: Input: s1 - "DataStructures Issss###Fun", s2 - "DataStructures Iszwp###Fun" Output: true Explanation: Both s1 and s2 become "DataStructuresIsFun". Example 2: Input: S- "abc##", T="Wc#d#" Output: false Explanation: s1 becomes "awhile s2 becomes "w" --Function Template import java.util.Stack; public class Lab3 { public static void main (String[] args) { String s1 = "DataStructuresIssss###Fun"; String 52 = "DataStructuresIszwp###Fun"; boolean ans = backspaceCompare(s1, s2); System.out.println(ans); // Should be True } public static boolean backspaceCompare(String si, String s2){ Stack
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
