随笔分类 -  LeetCode

数组中出现次数超过一半的数字
摘要://方案一: O(N)? 不适合海量数据int* maxK(int A[] , const int& n, const int& k){ if(np) --end; if(begin>=end) return begin; swap(A[begin],A[end]); ... 阅读全文

posted @ 2014-07-22 17:04 Sara Chi 阅读(121) 评论(0) 推荐(0)

Sort List
摘要:Sort a linked list inO(nlogn) time using constant space complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * L... 阅读全文

posted @ 2014-06-03 16:37 Sara Chi 阅读(133) 评论(0) 推荐(0)

Max Points on a Line
摘要:Givennpoints on a 2D plane, find the maximum number of points that lie on the same straight line./** * Definition for a point. * struct Point { * ... 阅读全文

posted @ 2014-06-03 11:38 Sara Chi 阅读(187) 评论(0) 推荐(0)

Evaluate Reverse Polish Notation
摘要:Evaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another express... 阅读全文

posted @ 2014-05-21 23:48 Sara Chi 阅读(126) 评论(0) 推荐(0)

Binary Tree Inorder Traversal
摘要:Given a binary tree, return theinordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,3,2].Note... 阅读全文

posted @ 2014-05-21 23:18 Sara Chi 阅读(113) 评论(0) 推荐(0)

Best Time to Buy and Sell Stock II
摘要:Say you have an array for which theithelement is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete a... 阅读全文

posted @ 2014-05-21 23:07 Sara Chi 阅读(88) 评论(0) 推荐(0)

Unique Binary Search Trees
摘要:Givenn, how many structurally uniqueBST's(binary search trees) that store values 1...n?For example,Givenn= 3, there are a total of 5 unique BST's. 1... 阅读全文

posted @ 2014-05-21 23:02 Sara Chi 阅读(110) 评论(0) 推荐(0)

Reverse digits of an integer.
摘要:Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321 1 class Solution { 2 public: 3 int reverse(int x) { 4 ... 阅读全文

posted @ 2014-05-21 22:58 Sara Chi 阅读(255) 评论(0) 推荐(0)

Same Tree
摘要:Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical an... 阅读全文

posted @ 2014-05-21 22:52 Sara Chi 阅读(126) 评论(0) 推荐(0)

Maximum Depth of Binary Tree
摘要:Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest le... 阅读全文

posted @ 2014-05-21 22:47 Sara Chi 阅读(97) 评论(0) 推荐(0)

Single Number
摘要:Given an array of integers, every element appearstwiceexcept for one. Find that single one.Note:Your algorithm should have a linear runtime complexity... 阅读全文

posted @ 2014-05-21 22:40 Sara Chi 阅读(132) 评论(0) 推荐(0)

Reverse Words in a String
摘要:Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the". 1 Class Solution{ 2 public: ... 阅读全文

posted @ 2014-05-21 21:10 Sara Chi 阅读(158) 评论(0) 推荐(0)