- 博客(112)
- 收藏
- 关注
原创 C++静态类型成员变量的初始化顺序
面试的时候被问到C++静态类型成员变量的初始化顺序是否和声明的顺序一致?对于非静态成员变量的初始化顺序一般都比较熟悉,非静态成员的初始化顺序只和在类定义体内声明的顺序有关,而C++静态类型成员变量的初始化顺序是否也和声明的顺序一致?对于这个问题我使用下面的程序测试了下得到的答案是:C++静态类型成员变量的初始化顺序和声明的顺序不一致,和初始化语句的先后顺序有关。测试程序1:
2016-09-19 14:37:11
4249
1
原创 求两个有序数组两两相加的值最小的K个数
题目描述:有两个大小分别是lenA和lenB的数组A,B,它们元素的按非递减有序排列,找出这样的k个最小的(ai + bj) ,其中 0例如对于:A = 1,2,3,4B = 2,3,4,5ai+bj的所有组合有4*4 = 16个,如下图:b\a 1 2 3 42 3 4 5 63 4 5
2016-08-06 13:29:30
2629
原创 Copy List with Random Pointer
题目描述: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.解题思路:使用hashtable保存原
2016-08-05 15:41:06
356
原创 Single Number
题目描述:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it withou
2016-08-05 14:51:40
203
原创 Candy
题目描述:There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must have
2016-08-05 14:42:59
562
原创 Gas Station
题目描述:There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from stat
2016-08-05 14:13:04
352
原创 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[
2016-07-31 11:01:30
203
原创 Surrounded Regions
题目描述:Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For e
2016-07-31 10:32:25
214
原创 Sum Root to Leaf Numbers
题目描述:Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Fi
2016-07-31 10:15:22
193
原创 Longest Consecutive Sequence
题目描述: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 longest consecutive elements sequence
2016-07-29 15:36:22
208
原创 Word Ladder II
题目描述:Given two words (beginWord and endWord), and a dictionary's word list, find all shortest transformation sequence(s) from beginWord toendWord, such that:Only one letter can be changed at
2016-07-29 13:59:24
277
原创 Binary Tree Maximum Path Sum
题目描述:Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connec
2016-07-28 21:31:05
258
原创 Best Time to Buy and Sell Stock III
题目描述: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 at most two transactions.Note
2016-07-28 20:21:03
256
原创 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],
2016-07-28 19:26:38
203
原创 Populating Next Right Pointers in Each Node
题目描述:Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next r
2016-07-27 21:14:49
198
原创 Flatten Binary Tree to Linked List
题目描述:Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look li
2016-07-27 20:26:39
235
原创 Path Sum II
题目描述:Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5
2016-07-27 19:31:09
201
原创 Binary Tree Zigzag Level Order Traversal
题目描述:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Gi
2016-07-27 11:08:55
186
原创 Binary Tree Level Order Traversal
题目描述:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3
2016-07-27 10:56:43
226
原创 Validate Binary Search Tree
题目描述:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the no
2016-07-26 21:54:11
227
原创 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
2016-07-24 10:29:31
202
原创 Remove Duplicates from Sorted Array II
题目描述: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 should return length = 5, with t
2016-07-21 19:41:13
140
原创 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
2016-07-21 19:26:20
421
原创 Subsets
题目描述:Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.For example,If nums = [1,2,3], a solution is:[
2016-07-21 19:08:27
172
原创 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],
2016-07-20 21:55:05
312
原创 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 th
2016-07-20 21:15:41
229
原创 Search a 2D Matrix
题目描述: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 from left to right.The first inte
2016-07-20 20:45:12
197
原创 Edit Distance
题目描述:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted
2016-07-20 20:06:07
208
原创 Simplify Path
题目描述:Given an absolute path for a file (Unix-style), simplify it.For example,path = "/home/", => "/home"path = "/a/./b/../../c/", => "/c"解题思路:在Unix-style系统中"."表示当前目录,".."表示上一级目录。因此
2016-07-20 19:45:36
178
原创 Climbing Stairs
题目描述:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?解题思路:使用动态规划,状态dp[
2016-07-20 19:23:40
187
原创 Minimum Path Sum
题目描述:Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down
2016-07-20 16:20:40
192
原创 Unique Paths II
题目描述:Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectivel
2016-07-20 15:39:30
192
原创 Unique Paths
题目描述:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to
2016-07-20 15:24:22
161
原创 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,
2016-07-20 14:37:32
163
原创 Insert Interval
题目描述:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start
2016-07-19 21:26:23
205
原创 Merge Intervals
题目描述:Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].解题思路:基于间隔的start属性进行升序排序,然后一趟遍历合并存在重叠的间隔
2016-07-19 21:02:11
139
原创 Jump Game
题目描述:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.
2016-07-19 20:47:05
146
原创 Spiral Matrix
题目描述:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8,
2016-07-19 20:16:58
175
原创 Maximum Subarray
题目描述:Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4
2016-07-19 19:29:31
165
原创 Group Anagrams
题目描述:Given an array of strings, group anagrams together.For example, given: ["eat", "tea", "tan", "ate", "nat", "bat"], Return:[ ["ate", "eat","tea"], ["nat","tan"], ["bat"]]
2016-07-17 15:14:45
190
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人