- 博客(8)
- 收藏
- 关注
原创 Lowest Common Ancestor of a Binary Search Tree
Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST. According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betwee
2015-07-24 15:11:13 347
原创 Path Sum
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ clas
2015-07-24 14:29:11 264
原创 Intersection of Two Linked Lists
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode *ge
2015-07-24 14:08:54 285
原创 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-07-17 10:04:11 353
原创 Product of Array Except Self
For example, given [1,2,3,4], return [24,12,8,6].class Solution { public: vector productExceptSelf(vector& nums) { int zerocount=0; int multi=1; int zeroflag;
2015-07-16 10:57:43 416
原创 pow(double x,int n)
class Solution { public: double myPow(double x, int n) { if(n==0) return 1; if(n==1) return x; if(x==1) return 1; if(n>0){ if(n&1){ return myPow
2015-07-16 10:56:18 630
原创 斐波那契数列
第n项为n个{1,1,1,0}矩阵相乘结果的首项。#include using namespace std; typedef long long LL; const LL mod=1000000009; const int Q=2; struct matrix { LL a[Q][Q]; }; matrix base={1,1,1,0},one={1,0,0,1}; matrix m_mu
2015-07-15 08:46:48 371
原创 最大子序列和
#include using namespace std; int maxarray1(int* a,int n)///////// { int maxsum=0,thissum; for(int i=0;i<n;i++) { thissum=0; for(int j=0;j<n;j++) { thissum+=a[j]; if(thissum>maxsum)
2015-07-11 12:28:07 351
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人