摘要: https://leetcode-cn.com/problems/reverse-words-in-a-string/ 思路:删除多余的空格,修好一个方法,给一定范围,翻转一定范围的字符串 public static String reverseWords(String s) { if (s == 阅读全文
posted @ 2021-06-27 17:16 syh-918 阅读(47) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/valid-anagram/ 思路1 统计字符数哈希表 思路2 使用数组记录出现次数 public boolean isAnagram(String s, String t) { if (s == null || t == null) 阅读全文
posted @ 2021-06-27 17:04 syh-918 阅读(65) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/subtree-of-another-tree/ public boolean isSubtree(TreeNode s, TreeNode t) { if (s == null || t == null) return false; 阅读全文
posted @ 2021-06-27 16:44 syh-918 阅读(57) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/flipped-string-lcci/ 思路1: 将目标字符串 s1,拼接上自己,判断给的字符串是否是当前拼接字符串的子串; public static boolean isRevolving(String s1, String s 阅读全文
posted @ 2021-06-27 16:38 syh-918 阅读(38) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/daily-temperatures/ 思路1: 使用单调递减栈 public int[] dailyTemperatures(int[] T) { if (T == null || T.length == 0) return nul 阅读全文
posted @ 2021-06-27 15:02 syh-918 阅读(47) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/maximum-binary-tree/ 思路1:用递归的思想来解决问题 思路2: 利用栈来解决,找出左边第一个比较大值,和右边第一个比较大值,两两比较取大的一个 public TreeNode constructMaximumBin 阅读全文
posted @ 2021-06-27 14:55 syh-918 阅读(46) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/sliding-window-maximum/ 思路0:直接遍历,对比k个元素。 思路1:先确认最大值数组个数,踢出掉不能作为滑动窗口的第一个值。使用双端队列来解决问题,双端队列保存的是索引 思路2:对暴力法的优化,记录下上一次的最大 阅读全文
posted @ 2021-06-26 21:41 syh-918 阅读(51) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/min-stack/ 思路1 空间换时间思想 ,内部初始化一个正常栈,另一个村最小栈,push进一个值后 最小栈内也要push进当前最小值。 思路2 依然还是空间换时间,使用链表来实现 public class MinStack { 阅读全文
posted @ 2021-06-26 21:36 syh-918 阅读(33) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/palindrome-linked-list/ 思路1: 先判断链表节点为空,为一个,为两个的情况,利用快慢指针找到中间节点,翻转部分节点 思路2: 先判断链表节点为空,为一个,为两个的情况,翻转链表然后对比(空间复杂度不符合) 思路 阅读全文
posted @ 2021-06-26 18:35 syh-918 阅读(41) 评论(0) 推荐(0)
摘要: https://leetcode-cn.com/problems/partition-list/ 思路 各自的部分弄成一个链表然后头尾相接,用到虚拟节点 代码 public ListNode partition(ListNode head, int x) { if (head == null) re 阅读全文
posted @ 2021-06-26 18:14 syh-918 阅读(47) 评论(0) 推荐(0)