leetcode
Peppermint__
这个作者很懒,什么都没留下…
展开
-
LeetCode 23.Merge k Sorted List 合并k个有序链表(后补)
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 题目描述 讲k个有序链表合并为一个链表,并且保持有序状态。 思路1 将所有的链表的头结点放到最小堆里面,每提取一个结点,就将该结点的下一个结点放在堆里。public class MergeKSort原创 2018-02-26 16:46:51 · 172 阅读 · 0 评论 -
Leetcode Permutation sequence
The set[1,2,3,…,n]contains a total of n! unique permutations. By listing and labeling all of the permutations in order, We get the following sequence (ie, for n = 3): “123” “132” “213”原创 2018-02-24 22:02:18 · 168 阅读 · 0 评论 -
LeetCode 72. Edit Distance 115. Distinct Subsequences 字符串 DP
72. Edit Distance Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.) You have the following 3 operati...原创 2018-02-28 11:03:00 · 145 阅读 · 0 评论 -
LeetCode 90. Subsets II 递归
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.For example, If nums = [1,2,2]原创 2018-02-28 10:42:56 · 220 阅读 · 0 评论 -
LeetCode 93. Restore IP Addresses 递归,分治
Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example: Given “25525511135”, return [“255.255.11.135”, “255.255.111.35”]. (O原创 2018-02-28 09:47:56 · 225 阅读 · 0 评论 -
LeetCode 96. Unique Binary Search Trees 1&2
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example, Given n = 3, there are a total of 5 unique BST’s. 题目链接题目描述 给定n个不同元素,求可以构成多少种BST? 思路 这一原创 2018-02-27 11:49:22 · 150 阅读 · 0 评论 -
二叉树的遍历 迭代 LeetCode 94 144 145
这里简要介绍一下树的迭代方式遍历前序遍历 leetcode 94 使用栈来模拟递归,出栈时候访问结点。前序遍历先访问左子树,再访问右子树,那么入栈时相反,即先入右子树,再入左子树。那么出栈的时候就是前序遍历的顺序。 class PreOrder { ArrayList<Integer> result = new ArrayList<>(); public ArrayList<I原创 2018-02-27 11:23:16 · 148 阅读 · 0 评论 -
LeetCode 4. Median of Two Sorted Arrays
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 (m+n)). Example 1: nums1 =原创 2018-02-26 17:09:49 · 138 阅读 · 0 评论 -
LeetCode 148.Sort List 链表排序
Sort a linked list in O(n log n) time using constant space complexity. 题目链接 题目大意 对一个链表进行排序,复杂度在O(nlogn)内。 思路 我写的是归并排序,注意分开后的左边链表的尾结点的next置null。 public class SortList { public ListNode原创 2018-02-26 16:34:46 · 465 阅读 · 0 评论 -
LeetCode 25. Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to the length of the linked list. If the number of原创 2018-02-26 17:00:10 · 138 阅读 · 0 评论 -
数据结构 链表知识及常用操作(Java)
在链表的各种问题中,经常需要用到找中间结点,类似二分法,这时候就需要一个快慢指针的方法。public ListNode getMiddle(ListNode head) { if ( head==null || head.next==null ) return head; ListNode slow = head,fast = head; while原创 2018-02-24 23:28:13 · 279 阅读 · 0 评论