LeetCode
文章平均质量分 76
Laegolas
正在加载中......
展开
-
Sort List [LeetCode]
Sort a linked list in O(n log n) time using constant space complexity.自己写了快排的想法,不过实现的很蛋疼,加上搜索的了其他的人的想法,总结了基本的3种实现方法第一种:快排的思想,输出结果一直没问题,提交就提示Time Limit Exceeded,调了好久没用,后来参考:http://blog.csdn.net原创 2014-03-15 12:53:58 · 595 阅读 · 0 评论 -
Reorder List[LeetCode]
Reorder ListGiven 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,Giv原创 2014-04-13 14:20:41 · 763 阅读 · 0 评论 -
Insertion Sort List[LeetCode]
Insertion Sort List Sort a linked list using insertion sort./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int原创 2014-04-13 10:13:21 · 559 阅读 · 0 评论 -
Merge Two Sorted Lists [LeetCode]
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.//Definition for singly-linked list.#include using name原创 2014-03-15 12:30:41 · 573 阅读 · 0 评论 -
Populating Next Right Pointers in Each Node and II[LeetCode]
Populating Next Right Pointers in Each Node Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each原创 2014-03-29 09:12:59 · 696 阅读 · 0 评论 -
Implement strStr() [LeetCode] + KMP
Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.实现了下,KMP算法明显速度提高y原创 2014-05-08 15:36:00 · 988 阅读 · 0 评论 -
Pascal's Triangle [LeetCode]
Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]原创 2014-04-11 10:08:11 · 465 阅读 · 0 评论 -
N-Queens And N-Queens II [LeetCode] + Generate Parentheses[LeetCode] + 回溯法
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.原创 2014-05-08 10:09:05 · 1083 阅读 · 0 评论 -
Multiply Strings[LeetCode]
Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.class Solution {public: string mult原创 2014-03-16 10:29:44 · 563 阅读 · 0 评论 -
Reverse Words in a String[LeetCode]
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Clarification:What constitutes a word?A sequence of non-sp原创 2014-03-15 13:02:49 · 716 阅读 · 0 评论