- 博客(13)
- 收藏
- 关注
原创 23. Merge k Sorted Lists
题目:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.直接想法是连接相邻的链表,需要遍历两个链表,复杂度为n,然后将链表容器遍历一遍,也是n,总时间复杂度为O(n^2)然后想到O(nlogn)的方法,可以用到归并排序算法
2017-07-31 21:43:39 275
原创 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...
2017-07-29 16:41:58 197
原创 链表算法题技巧总结
1.旋转链表,遍历一遍求链表长度,将链表首尾相接再断开(61.rorate)2.将两条排序链表连接,直接连接即可(21.mergetwolist)3.当提示越界时,应该注意左式不为NULL,右式可为NULL,如 p->next==p->next->next条件满足p->next!=NULL即可或者是两次引用成员,如p->next->val,如果p->
2017-07-28 21:06:53 726
原创 82. Remove Duplicates from Sorted List II
题目:Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Give
2017-07-28 21:03:17 333
原创 83.Remove Duplicates from Sorted List
题目:Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3.class Solu
2017-07-28 21:01:58 328
原创 86. Partition List
题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes i
2017-07-28 20:09:55 206
原创 21. Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.水题自己写的classSolut
2017-07-28 16:21:16 250
原创 75. Sort Colors 快速排序
题目:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the in
2017-07-28 15:06:58 536
原创 格雷码的算法实现
在正序的基础上将1左移n-1位,再加在逆序上,即得green code 格雷码。算法返回的是10进制的值class Solution {public: vector grayCode(int n) { vector res; res.push_back(0); int inc=1; for(int i=0
2017-07-27 15:14:08 1658
原创 90. Subsets II 子集列举
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,2], a solutio
2017-07-27 09:21:38 187
原创 从leetcode 92.reverse-linked-list-ii 对链表的认识
题目:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL, m = 2 and n = 4,return1->4->3->2->5->NULL.Note: Given m, n satis
2017-07-25 17:00:35 344
原创 对于BST(二分搜索树)中lower 和upper的技巧
题目1:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node'
2017-07-25 15:48:13 321
原创 前序遍历 中序遍历 后续遍历的递归与非递归算法
1.preorder 前序遍历2.inorder 中序遍历class Solution {public: vector inorderTraversal(TreeNode *root) { vector v; if(root==NULL) return v; inorder(root,v);
2017-07-25 15:45:04 371
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人