- 博客(17)
- 资源 (1)
- 收藏
- 关注
原创 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 in each of
2015-01-31 16:50:46
630
原创 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.#include#includeusing namespace std;//Definition fo
2015-01-31 14:56:51
587
原创 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.解题思路:一般而言,合并两个有序链表较为简单,只需要两两逐个比较即可.而本题要求合并K个有序链表,事实上只需要对每个链表的头结点建堆.每次输出最小值.并插入其所在链表的下个结点并维护堆.可以利用S
2015-01-31 13:48:22
586
原创 Intersection of Two Linked Lists
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 ↘
2015-01-30 19:42:00
706
原创 Add Two Numbers
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link
2015-01-30 14:21:09
679
原创 Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.解题思路:采用中序排列的方法递归地决定每个结点的数值;#include#include#includeusing namespace std;//Definition
2015-01-30 12:59:30
713
原创 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve
2015-01-30 00:24:17
809
原创 two sum
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe
2015-01-29 19:25:50
621
原创 Substring with Concatenation of All Words
You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without
2015-01-29 13:30:29
604
原创 Minimum Window Substring
Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For example,S = "ADOBECODEBANC"T = "ABC"Minimum window is "BAN
2015-01-28 22:16:40
498
原创 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. Fo
2015-01-28 14:06:00
430
原创 4SUM
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Element
2015-01-27 17:04:52
497
原创 Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n
2015-01-26 19:03:24
455
原创 Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4],
2015-01-26 00:31:33
459
原创 Subsets II
Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplica
2015-01-24 23:49:29
503
原创 Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ],
2015-01-24 15:20:40
394
原创 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 integers 0,
2015-01-23 23:45:31
615
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅