直接用栈后进先出的特性实现列表的反转
Zero-complexity Transposition
https://www.nowcoder.com/practice/c54775799f634c72b447ef31eb36e975
import java.util.Scanner; import java.util.Stack; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Stack<Integer> stack = new Stack<>(); while (n-- > 0) { stack.push(sc.nextInt()); } while (!stack.isEmpty()) { System.out.print(stack.pop() + " "); } } }