2390. Removing Stars From a String - Medium 前往題目 想法 Stack 思路這題很簡單遇到米字號直接pop Codeclass Solution { public String removeStars(String s) { Stack<Character> stack = new Stack(); for (char c : s.toCharArray()) { // Encounter * if (c == '*') { stack.pop(); } else { stack.push(c); } } StringBuilder sb = new StringBuilder(); while (!stack.isEmpty()) { sb.insert(0, stack.pop()); } return sb.toString(); } } Leetcode > Medium #Leetcode #心得 #Stack #String #Simulation 2390. Removing Stars From a String - Medium https://f88083.github.io/2024/08/06/2390-Removing-Stars-From-a-String-Medium/ 作者 Simon Lai 發布於 2024年8月6日 許可協議 946. Validate Stack Sequences - Medium 上一篇 1544. Make The String Great - Easy 下一篇 Please enable JavaScript to view the comments