随笔分类 -  Leetcode (C++)

上一页 1 ··· 4 5 6 7 8 9 10 下一页

83. Remove Duplicates from Sorted List (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,... 阅读全文

posted @ 2015-10-03 11:31 joannae 阅读(165) 评论(0) 推荐(0)

80. Remove Duplicates from Sorted Array II (Array)
摘要:Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, Given sorted array nums = [1,1,1,2,2,3], Your function s 阅读全文

posted @ 2015-10-03 11:30 joannae 阅读(122) 评论(0) 推荐(0)

143. Reorder List(List)
摘要: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 ... 阅读全文

posted @ 2015-10-03 11:22 joannae 阅读(225) 评论(0) 推荐(0)

61. Rotate List(List)
摘要:Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->... 阅读全文

posted @ 2015-10-03 10:57 joannae 阅读(148) 评论(0) 推荐(0)

92. Reverse Linked List II (List)
摘要:Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2 阅读全文

posted @ 2015-10-03 10:36 joannae 阅读(183) 评论(0) 推荐(0)

86. Partition List (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 o... 阅读全文

posted @ 2015-10-03 10:29 joannae 阅读(142) 评论(0) 推荐(0)

148. Sort List (List)
摘要:Sort a linked list in O(n log n) time using constant space complexity. 法I:快排。快排的难点在于切分序列。从头扫描,碰到>=target的元素,停止;从第二个字串扫描,碰到<=target的元素停止;交换这两个元素。这样的好处是 阅读全文

posted @ 2015-10-03 09:41 joannae 阅读(184) 评论(0) 推荐(0)

147. Insertion Sort List (List)
摘要:Sort a linked list using insertion sort. 阅读全文

posted @ 2015-10-03 09:39 joannae 阅读(152) 评论(0) 推荐(0)

128. Longest Consecutive Sequence (HashTable)
摘要:Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The long 阅读全文

posted @ 2015-10-03 09:28 joannae 阅读(217) 评论(0) 推荐(0)

75. Sort Colors (Array)
摘要: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, ... 阅读全文

posted @ 2015-10-03 08:34 joannae 阅读(199) 评论(0) 推荐(0)

88. Merge Sorted Array (Array)
摘要:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size tha... 阅读全文

posted @ 2015-10-03 07:56 joannae 阅读(148) 评论(0) 推荐(0)

30. Substring with Concatenation of All Words (String; HashTable)
摘要:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a conca 阅读全文

posted @ 2015-09-20 13:51 joannae 阅读(205) 评论(0) 推荐(0)

29. Divide Two Integers (INT; Overflow, Bit)
摘要:Divide two integers without using multiplication, division and mod operator. If it is overflow, return MAX_INT. 思路I:做减法,直到被除数<除数。但结果 Time Limit Exceed 阅读全文

posted @ 2015-09-17 06:40 joannae 阅读(283) 评论(0) 推荐(0)

28. Implement strStr() (String)
摘要:Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.class Solution {public: ... 阅读全文

posted @ 2015-09-16 08:43 joannae 阅读(178) 评论(0) 推荐(0)

27.Remove Element(Array)
摘要:Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't mat... 阅读全文

posted @ 2015-09-15 10:31 joannae 阅读(134) 评论(0) 推荐(0)

26.Remove Duplicates from Sorted Array(Array)
摘要:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space fo 阅读全文

posted @ 2015-09-15 10:28 joannae 阅读(145) 评论(0) 推荐(0)

25.Reverse Nodes in k-Group (List)
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then l 阅读全文

posted @ 2015-08-23 08:59 joannae 阅读(203) 评论(0) 推荐(0)

24.Swap Nodes in Pairs (List; Two-Pointers)
摘要:Given a linked list, swap every two adjacent nodes and return its head.For example,Given1->2->3->4, you should return the list as2->1->4->3.Your algor... 阅读全文

posted @ 2015-08-12 21:13 joannae 阅读(248) 评论(0) 推荐(0)

23.Merge k Sorted Lists (Array, Queue; Sort)
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 思路I: 选择排序 每次都比较各个list的头指针所指的val,取最小的那个。时间复杂度O(n*k) 阅读全文

posted @ 2015-08-11 18:45 joannae 阅读(214) 评论(0) 推荐(0)

22.Generate Parentheses (String; Back-Track)
摘要:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: " 阅读全文

posted @ 2015-08-05 18:49 joannae 阅读(186) 评论(0) 推荐(0)

上一页 1 ··· 4 5 6 7 8 9 10 下一页

导航