Lowest Common Ancestor of a Binary Tree Total Accepted: 6162 Total Submissions: 23311 My Submissions Question Solution
Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in...
分类:
其他好文 时间:
2015-07-26 19:23:17
阅读次数:
192
Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity...
分类:
其他好文 时间:
2015-07-26 19:03:17
阅读次数:
103
http://poj.org/problem?id=1308#include#include#include#include#include#define N 110#define INF 0xfffffffusing namespace std;int f[N],vis[N];int Find(i...
分类:
其他好文 时间:
2015-07-26 17:05:43
阅读次数:
110
题目:
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 k transactions.
Note:
Y...
分类:
编程语言 时间:
2015-07-26 15:56:12
阅读次数:
142
题目:
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:
...
分类:
编程语言 时间:
2015-07-26 15:53:12
阅读次数:
155
Kth Smallest Element in a BST
Given a binary search tree, write a function kthSmallestto find the kth
smallest element in it.
Note:
You may assume k is always valid, 1 ≤ k ≤ BST's total elem...
分类:
其他好文 时间:
2015-07-26 15:52:22
阅读次数:
125
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.
Find the tota...
分类:
其他好文 时间:
2015-07-26 15:50:28
阅读次数:
113
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: a...
分类:
其他好文 时间:
2015-07-26 15:30:45
阅读次数:
98
题目如下:
Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1 * p2^k2 *…*pm^km.
Input Specification:
Each input file contai...
分类:
其他好文 时间:
2015-07-26 14:18:45
阅读次数:
124
1.在使用mp[key]的时候它会去找键值为key的项,如果没有,他会自动添加一个key的项,再把value赋值为相应的初始值(value是int的话赋值为0,string的话赋值为空)。所以如果是插入的话可以用insert,如果是查找的话可以使用find,这样可以节省开销。查找的时间复杂度为O(logn)
2.
代码:#include
#include
#include
using ...
分类:
其他好文 时间:
2015-07-26 12:49:38
阅读次数:
160