摘要:
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 阅读全文
摘要:
public class RemoveOutermostParentheses { /* 解法一:栈,( 进栈,) 出栈,栈为空时,则找到原语,然后去括号。 */ public String removeOuterParentheses(String S) { StringBuilder sb=new StringBuilder(); ... 阅读全文
摘要:
/* 解法一:使用链表从0实现栈,用min来存放最小值。 复杂的地方是,如果pop了最小的数,就要遍重新找到最小的数。 */ public class MinStack { List list; int min; /** initialize your data structure here. */ public MinStack... 阅读全文
摘要:
public class RemoveAllAdjacentDuplicatesInString { /* 解法一:栈 */ public String removeDuplicates(String S) { Stack<Character> stack=new Stack<>(); for (char c:S.toCharArray()){ if (stack.isEmpty()||c!=st 阅读全文
摘要:
public class RemoveDuplicatesFromSortedList { public ListNode deleteDuplicates(ListNode head) { ListNode current=head; while (current!=null&¤t.next!=null){ if (current.val==current.next.val) cur 阅读全文
摘要:
public class MergeTwoSortedLists { /* 解法一:迭代 */ public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if (l1==null) return l2; if (l2==null) ... 阅读全文
摘要:
public class IntersectionOfTwoLinkedList { /* 解法一:暴力遍历求交点。 时间复杂度:O(m*n) 空间复杂度:O(1) */ public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA==null||headB==null) return null; if 阅读全文
摘要:
public class PalindromeLinkedList { /* 解法一:可能刚开始刷题的原因,想到的老是这种简单的笨办法。 */ public static boolean isPalindrome(ListNode head) { if(head==null||head.next==null) return true; ListNode temp=head; List<Intege 阅读全文
摘要:
package LinedList;public class RemoveLinkedListElements { //解法一:循环 public ListNode removeElements(ListNode head, int val) { while (head!=null&&head.va 阅读全文
摘要:
package LinedList;public class ReverseASinglyLinkedList { //解法一:迭代。 public ListNode reverseList(ListNode head) { ListNode previous = null; ListNode cu 阅读全文