摘要:
Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.解题思路:本题主要需要考虑到斜线的情况,可以分别计算出过points[i]直线最多含几个点,然后算出最... 阅读全文
摘要:
Sort a linked list in O(n log n) time using constant space complexity.解题思路:归并排序、快速排序、堆排序都是O(n log n),由于优先级队列是用堆排序实现的,因此,我们使用优先级队列即可,JAVA实现如下: publi... 阅读全文
摘要:
Sort a linked list using insertion sort.解题思路:插入排序,JAVA实现如下: public ListNode insertionSortList(ListNode head) { if(head==null||head.next==null) ... 阅读全文
摘要:
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... 阅读全文
摘要:
Given a binary tree, return the postorder traversal of its nodes' values. For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,... 阅读全文
摘要:
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... 阅读全文
摘要:
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 ... 阅读全文
摘要:
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?解... 阅读全文
摘要:
Given a linked list, determine if it has a cycle in it. Follow up:Can you solve it without using extra space?解题思路:由于不让用extra space,所以用一个快指针和一个慢指针,快指针一... 阅读全文
摘要:
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such po... 阅读全文
摘要:
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For e... 阅读全文