import java.util.*; public class Solution { /** * 反转字符串 * @param str string字符串 * @return string字符串 */ public String solve (String str) { if (str == null || str.length() == 0) { return str; } Stack<Character> stack = new Stack<>(); char[] chars = str.toCharArray(); for (char c : chars) { stack.push(c); } StringBuilder result = new StringBuilder(); while (!stack.isEmpty()) { result.append(stack.pop()); } return result.toString(); } }