ValidString
https://leetcode.com/discuss/interview-question/1557009/amazon-online-coding-assessment-sde-2
static boolean isValid(String s) { Stack<Character> st = new Stack<>(); for(char c : s.toCharArray()){ if(st.isEmpty()){ st.push(c); }else if(st.peek() == c){ st.pop(); }else{ st.push(c); } } return st.isEmpty(); }
Last updated