上一页 1 2 3 4 5 6 ··· 14 下一页
摘要: public class DailyTemperatures { /* 解法一:暴力 */ public int[] dailyTemperatures(int[] T) { int[] result=new int[T.length]; for (int i=0;i<T.length;i++){ for (int j=i+1;j<T.length;j++){ if (T[j]>T[i]){ re 阅读全文
posted @ 2019-09-27 11:24 张玉昊 阅读(209) 评论(0) 推荐(0) 编辑
摘要: public class RemoveOutermostParentheses { /* 解法一:栈,( 进栈,) 出栈,栈为空时,则找到原语,然后去括号。 */ public String removeOuterParentheses(String S) { StringBuilder sb=new StringBuilder(); ... 阅读全文
posted @ 2019-09-23 14:48 张玉昊 阅读(226) 评论(0) 推荐(0) 编辑
摘要: /* 解法一:使用链表从0实现栈,用min来存放最小值。 复杂的地方是,如果pop了最小的数,就要遍重新找到最小的数。 */ public class MinStack { List list; int min; /** initialize your data structure here. */ public MinStack... 阅读全文
posted @ 2019-09-19 13:09 张玉昊 阅读(131) 评论(0) 推荐(0) 编辑
摘要: public class RemoveAllAdjacentDuplicatesInString { /* 解法一:栈 */ public String removeDuplicates(String S) { Stack<Character> stack=new Stack<>(); for (char c:S.toCharArray()){ if (stack.isEmpty()||c!=st 阅读全文
posted @ 2019-09-08 13:06 张玉昊 阅读(261) 评论(0) 推荐(0) 编辑
摘要: public class RemoveDuplicatesFromSortedList { public ListNode deleteDuplicates(ListNode head) { ListNode current=head; while (current!=null&&current.next!=null){ if (current.val==current.next.val) cur 阅读全文
posted @ 2019-09-08 10:55 张玉昊 阅读(153) 评论(0) 推荐(0) 编辑
摘要: public class MergeTwoSortedLists { /* 解法一:迭代 */ public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if (l1==null) return l2; if (l2==null) ... 阅读全文
posted @ 2019-09-03 20:59 张玉昊 阅读(280) 评论(0) 推荐(0) 编辑
摘要: public class IntersectionOfTwoLinkedList { /* 解法一:暴力遍历求交点。 时间复杂度:O(m*n) 空间复杂度:O(1) */ public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA==null||headB==null) return null; if 阅读全文
posted @ 2019-09-03 13:30 张玉昊 阅读(234) 评论(0) 推荐(0) 编辑
摘要: public class PalindromeLinkedList { /* 解法一:可能刚开始刷题的原因,想到的老是这种简单的笨办法。 */ public static boolean isPalindrome(ListNode head) { if(head==null||head.next==null) return true; ListNode temp=head; List<Intege 阅读全文
posted @ 2019-09-01 10:23 张玉昊 阅读(278) 评论(0) 推荐(0) 编辑
摘要: package LinedList;public class RemoveLinkedListElements { //解法一:循环 public ListNode removeElements(ListNode head, int val) { while (head!=null&&head.va 阅读全文
posted @ 2019-08-15 11:15 张玉昊 阅读(159) 评论(0) 推荐(0) 编辑
摘要: package LinedList;public class ReverseASinglyLinkedList { //解法一:迭代。 public ListNode reverseList(ListNode head) { ListNode previous = null; ListNode cu 阅读全文
posted @ 2019-08-15 11:15 张玉昊 阅读(176) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 ··· 14 下一页