摘要: 后序遍历:左右中,和前序遍历(中左右)只差了一点,只需调整结果顺序和左右节点入栈顺序即可。 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNod 阅读全文
posted @ 2022-02-08 16:30 livingsu 阅读(35) 评论(0) 推荐(0)
摘要: 思路:用两个队列,先放到s2中,然后把s1的全部放入s2中,再将s1和s2进行交换即可。 class MyStack { Deque<Integer> s1=new ArrayDeque<>(); Deque<Integer> s2=new ArrayDeque<>(); public MyStac 阅读全文
posted @ 2022-02-08 10:58 livingsu 阅读(39) 评论(0) 推荐(0)
摘要: 一、题目 字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回左旋转两位得到的结果"cdefgab"。 示例 1: 输入: s = "abcdefg", k = 2 输出: "cdefgab 阅读全文
posted @ 2022-02-08 09:43 livingsu 阅读(29) 评论(0) 推荐(0)