import java.util.*; class Solution { public int solution(String s) { int answer = 0; Stack stack = new Stack(); for (String word : s.split(" ")) { if (word.equals("Z")) { stack.pop(); } else { stack.push(Integer.parseInt(word)); } } for (int i : stack) { answer += i; } return answer; } }