- 博客(11)
- 问答 (2)
- 收藏
- 关注
原创 leetcode No147. Insertion Sort List
Question:Sort a linked list using insertion sort.Algorithm:新建一个链表,模仿插入排序的过程Accepted Code:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next;
2016-10-29 11:59:58 557
原创 leetcode No143. Reorder List
Question: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
2016-10-29 11:15:38 504
原创 leetcode No142. Linked List Cycle II
Question:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Algorithm:首先fast每次走两步,slow每次走1步,如果fast走到NULL,说明没有环,如果fast和slow相遇,说明有环,假设fast和slow在Z相遇,
2016-10-27 19:57:45 453
原创 leetcode No23. Merge k Sorted Lists
Question:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Algorithm:1、把链表数组合并成一个链表2、对链表进行排序这应该不是个好办法、、、仅供参考Accepted Code:/** * Definit
2016-10-26 21:37:30 567
原创 leetcode No148. Sort List
Question:Sort a linked list in O(n log n) time using constant space complexity.Algorithm:类似归并排序,程序有注释Accepted Code:/** * Definition for singly-linked list. * struct ListNode { * int
2016-10-26 21:22:24 527
原创 leetcode No215. Kth Largest Element in an Array
Question:Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Given [3,2,1,5,6,4] and k
2016-10-25 16:08:36 489
原创 leetcode No160. Intersection of Two Linked Lists
Question:Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2016-10-20 21:24:38 699
原创 leetcode No233. Number of Digit One
Question:Given an integer n, count the total number of digit 1 appearing in all non-negative integers less than or equal to n.For example:Given n = 13,Return 6, because digit 1 occurred in
2016-10-15 20:55:32 651
原创 leetcode No138. Copy List with Random Pointer
Question:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.Algorithm:算
2016-10-12 19:29:17 737
转载 必须在类初始化列表中初始化的几种情况
原博地址:http://www.cnblogs.com/kaituorensheng/p/3477630.html1. 类成员为const类型2. 类成员为引用类型#include using namespace std;class A{ public: A(int &v) : i(v), p(v), j(v) {} vo
2016-10-11 09:14:33 2012
原创 leetcode No155. Min Stack
Question:Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.
2016-10-10 09:12:09 600
空空如也
hexo 搭建博客-hexo new出错
2017-03-16
stable_partition怎么实现的
2016-10-08
TA创建的收藏夹 TA关注的收藏夹
TA关注的人