- 博客(57)
- 资源 (3)
- 收藏
- 关注
原创 147. Insertion Sort List
Sort a linked list using insertion sort.题意:对链表进行插入排序。思路:每次对tail之后的结点操作,并适当更新tail(或head)。class Solution {public: ListNode* insertionSortList(ListNode* head) { if (head == NULL) return head
2016-05-31 16:18:08 232
原创 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 integers
2016-05-31 15:25:05 257
原创 331. Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as #.
2016-05-30 20:05:36 294
原创 71. Simplify Path
Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"click to show corner cases.Corner Cases:Did
2016-05-30 14:35:47 165
原创 173. Binary Search Tree Iterator
Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next()
2016-05-30 10:54:59 176
原创 150. Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",
2016-05-30 10:35:52 178
原创 145. Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solut
2016-05-30 10:05:55 248
原创 144. Binary Tree Preorder Traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive soluti
2016-05-30 08:47:46 196
原创 94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solutio
2016-05-30 08:32:43 170
原创 211. Add and Search Word - Data structure design
Design a data structure that supports the following two operations:void addWord(word)bool search(word)search(word) can search a literal word or a regular expression string containing only lett
2016-05-26 16:07:24 336
原创 131. Palindrome Partitioning
Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","
2016-05-26 14:55:53 203
原创 93. Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135",return ["255.255.11.135", "255.255.111.35"]. (Order
2016-05-23 22:04:02 154
原创 90. Subsets II
Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain du
2016-05-23 19:23:52 211
原创 89. Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of
2016-05-23 09:16:39 190
转载 C++运算符优先级
优先级操作符描述例子结合性1()[]->.::++--调节优先级的括号操作符数组下标访问操作符通过指向对象的指针访问成员的操作符通过对象本身访问成员的操作符作用域操作符后置自增操作符后置自减操作符(a + b) / 4;array[4] = 2;ptr->age = 34;obj.age = 34;
2016-05-23 09:00:55 205
原创 79. 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
2016-05-23 00:35:10 190
原创 78. Subsets
Given a set of distinct integers, nums, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.For
2016-05-22 22:50:17 192
原创 216. Combination Sum III
Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.Ensure that numbers wi
2016-05-22 16:31:06 205
原创 40. Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina
2016-05-22 15:34:05 206
原创 39. Combination Sum
Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb
2016-05-22 14:45:35 170
原创 77. Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2016-05-22 10:16:37 166
原创 60. Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3
2016-05-22 00:09:45 193
原创 47. Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].
2016-05-21 23:05:50 161
原创 46. Permutations
Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].题意:输出数
2016-05-21 22:25:54 156
原创 31. Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible
2016-05-21 21:17:37 203
原创 240. Search a 2D Matrix II
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in
2016-05-21 00:30:26 208
原创 295. Find Median from Data Stream
Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.Examples: [2,3,4] , the median
2016-05-20 23:01:45 715
原创 239. Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window
2016-05-20 00:15:18 598
原创 23. Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题意:合并k个有序链表为1个有序链表。思路:直接比较实现。比大小的过程从后向前执行。复杂度O(n*k) beats: 2.47%/** * Definition for singly-l
2016-05-19 17:32:00 325
原创 快排代码示例
快排是排序中的经典算法,最坏情况下复杂度是O(n^2),期望的时间复杂度是O(nlgn)。主要思想是:每次给一个元素x=A[r]找到其特定的位置,使左边的元素都小于x,右侧的值都大于x。如何实现就是用i来标记小于x的个数,然后没遇到一个小于x的值,就把i的范围值加1,并把这个较小的值置换进小于x的区域里。最后r前的元素都遍历完了,就把元素x与i+1位置上的元素置换,因为i+1这个位置,对应的就应该是
2016-05-19 14:51:32 5162 1
原创 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number
2016-05-18 22:52:36 411
原创 215. Kth Largest Element in an Array
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 = 2, return 5.
2016-05-18 22:15:23 334
原创 堆和堆排序
堆和堆排序堆和堆排序堆1 维护堆的性质2 建堆堆排序算法优先队列1. 堆(二叉)堆是一个数组,它可以看成是近似的完全二叉树,树上的每一个结点对应数组中的一个元素。结点A[i]的左右孩子结点对应为A[2i] & A[2i+1]。则A[i]的父结点为A[i/2](此处以及后文统一默认向下取整)。乘2与除2做操作在计算机中可以用移位操作实现,因此会比较快。由此可知这棵树除最后一层外,完全
2016-05-18 18:27:57 327
原创 343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, ret
2016-05-17 23:41:05 181
原创 338. Counting Bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5
2016-05-17 16:46:48 202
原创 322. Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money
2016-05-17 16:17:17 206
原创 122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on
2016-05-17 14:41:53 158
原创 304. Range Sum Query 2D - Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).The above rectangle (with the red bo
2016-05-17 12:39:06 195
原创 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest increasing subsequence is [2, 3, 7, 101], ther
2016-05-16 23:42:57 205
原创 279. Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n =
2016-05-16 22:36:57 220
CUDA编程指南
2016-04-18
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人