標籤:得到當天時間SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd" );String todayData = format.format(Calendar.getInstance().getTime()); 得到當月第一天public static String getMonthFirstDay() { SimpleDateFormat format = new
標籤:Sort a linked list using insertion sort.解題思路:插入排序,JAVA實現如下: public ListNode insertionSortList(ListNode head) { if(head==null||head.next==null) return head; ListNode root=new ListNode(Integer.MIN_VALUE); root.next=head;
標籤:Given a binary tree, return the preorder traversal of its nodes‘ values. For example:Given binary tree {1,#,2,3}, 1 2 / 3return [1,2,3].二叉樹的前序走訪,根節點→左子樹→右子樹解題思路一:遞迴實現,JAVA實現如下: public List<Integer>
標籤: Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes‘ values.For example,Given {1,2,3,4}, reorder
標籤:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return
標籤:題目:There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log
標籤:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up:Can you solve it without using extra space?解題思路,本題和上題十分類似,但是需要觀察出一個規律,參考LeetCode:Linked List Cycle IIJAVA實現如下: public ListNode