之前是通过hash来做,O(n)。这次为了熟悉通用性的解法,通过双指针来做。时间复杂度为O(nlogn)(即sort的复杂度)。主要是关于sort的用法上不太熟,关于自定义sort规则。C++ Reference中给的示例代码如下: 1 // sort algorithm example 2 #in...
分类:
其他好文 时间:
2014-10-31 11:30:15
阅读次数:
193
题目描述:
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node ...
分类:
其他好文 时间:
2014-10-30 22:42:12
阅读次数:
333
Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of ...
分类:
其他好文 时间:
2014-10-30 22:15:31
阅读次数:
334
今天出现的问题:Warning: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of in_array_two_di...
分类:
其他好文 时间:
2014-10-30 20:37:40
阅读次数:
174
Master-Mind HintsMasterMind is a game for two players. One of them, Designer, selects a secret code. The other, Breaker, tries to break it. A code is ...
分类:
其他好文 时间:
2014-10-30 14:51:07
阅读次数:
250
题目描述:
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.
代码:ListNode * Solution::mergeTwoLists(List...
分类:
其他好文 时间:
2014-10-30 11:44:34
阅读次数:
149
题目:Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints ...
分类:
编程语言 时间:
2014-10-30 07:09:03
阅读次数:
274
Power StringsTime Limit:3000MSMemory Limit:65536KTotal Submissions:33273Accepted:13825DescriptionGiven two strings a and b we define a*b to be their c...
分类:
其他好文 时间:
2014-10-29 23:34:33
阅读次数:
261
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time
complexity should be O(log (m+n)).
题意:寻找两个有序数组的中位数,要求复杂度为O(log
(m+...
分类:
其他好文 时间:
2014-10-29 22:23:33
阅读次数:
226
Currency ExchangeDescriptionSeveral currency exchange points are working in our city. Let us suppose that each point specializes in two particular cur...
分类:
编程语言 时间:
2014-10-29 21:19:21
阅读次数:
148