自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

西施豆腐渣

leetcode solutions by java, c++ and python

  • 博客(62)
  • 收藏
  • 关注

原创 leetcode A1: Lowest Common Ancestor of a Binary Tree Part I

Given a binary tree, find the lowest common ancestor of two given nodes in the tree. _______3______ / \ ___5__ ___1__ / \ / \

2013-01-31 16:51:30 1123

原创 careercup1.3: remove duplicate without extra space.

First, ask yourself, what does the interviewer mean by an additional bu#er? Can we use anadditional array of constant size? Algorithm—No (Large) Additional Memory:1.  For each character, check

2013-01-31 11:38:01 597

原创 careercup1.2: reverse a C-Style String.

Write code to reverse a C-Style String. (C-String means that “abcd” is represented as!ve characters, including the null character.) #include #include #include #include #include using nam

2013-01-31 09:56:11 781

原创 careercup 1.1: unique characters

Implement an algorithm to determine if a string has all unique characters.  What ifyou can not use additional data structures? package careercup;public class test1 { /*Implement an algorith

2013-01-31 08:26:18 985

原创 leetcode 66: Convert Sorted List to Binary Search Tree

Convert Sorted List to Binary Search TreeOct 3 '12Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-

2013-01-31 06:52:46 993

原创 leetcode 65: Same Tree

Same TreeSep 3 '12Given 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 and the nodes have the

2013-01-30 17:05:13 5866

原创 leetcode 64: Count and Say

Count and SayMar 6 '12The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...1 is read off as "one 1" or 11.11 is read off as

2013-01-30 15:51:44 901

原创 leetcode 63: Binary Tree Inorder Traversal

Binary Tree Inorder TraversalAug 27 '12Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3

2013-01-29 13:28:01 454

原创 leetcode 62: Best Time to Buy and Sell Stock III

Best Time to Buy and Sell Stock IIINov 7 '12Say 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

2013-01-29 08:53:58 604

原创 leetcode 61: Best Time to Buy and Sell Stock II

Best Time to Buy and Sell Stock IIOct 31 '12Say 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

2013-01-29 06:15:52 669

原创 leetcode 60: Anagrams

AnagramsMar 19 '12Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.class Solution {public: vector anagrams(ve

2013-01-28 21:50:30 2157

原创 G3: serialization and deserialization

serialization and deserialization a binary tree. void buildtree(TreeNode* &p, ifstream& ifs){ string token; readNextToken(ifs, token); while(token==","){ readNextToken(ifs, token); } if(to

2013-01-28 21:04:38 1191

原创 leetcode 59: Add Two Numbers

Add Two NumbersNov 1 '11You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two

2013-01-28 20:59:05 572

原创 leetcode 58: Add Binary

Add BinaryApr 2 '12Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".public class Solution { public String addBinary(S

2013-01-28 20:40:26 572

原创 leetcode 57: 3Sum Closest

3Sum ClosestJan 18 '12Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume

2013-01-27 14:06:37 540

原创 leetcode 56: Word Search

Word SearchApr 18 '12Given 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 tho

2013-01-27 09:48:44 862

原创 leetcode 55: Valid Palindrome

Valid PalindromeJan 13Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a pal

2013-01-26 20:16:31 2940

原创 leetcode 54: String to Integer (atoi)

String to Integer (atoi)Dec 27 '11Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask

2013-01-26 19:51:38 4122 1

原创 leetcode 53: Sqrt(x)

Sqrt(x)Apr 3 '12Implement int sqrt(int x).Compute and return the square root of x.class Solution {public: int sqrt(int x) { // Start typing your C/C++ solution b

2013-01-26 05:25:01 1500

原创 A4 : prime number within N

find prime number within n;  #include #include #include #include using namespace std;bool isPrime(int n) { if( n==2) return true; int temp = (int)sqrt( (double)n); for( int i=2; i<temp

2013-01-25 06:37:34 701

原创 leetcode 52: valid parentheses

Valid ParenthesesJan 30 '12Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct or

2013-01-25 05:00:06 624

原创 leetcode 51: Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "

2013-01-24 18:35:25 634

原创 G2: 大数加法

第一个数字是在数组里,第二个是个32bit uintuncompleted, not mine code.void add(vector & a, uint b){ int remainder = 0; int i; for(i = a.size() - 1; i > -1 && b > 0; --i)

2013-01-24 18:30:04 458

原创 leetcode 50: Valid Number

Apr 2 '12Validate if a given string is numeric.Some examples:"0" => true" 0.1 " => true"abc" => false"1 a" => false"2e10" => trueNote: It is intended for the problem statem

2013-01-24 18:22:46 767

原创 leetcode 49: Swap Nodes in Pairs

Feb 15 '12Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only

2013-01-23 16:03:52 546

原创 leetcode 48: Subsets II

Jun 25 '12Given a collection of integers that might contain duplicates, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set mu

2013-01-23 15:13:39 603

原创 A3: pythagorean

4. find out pythagorean triplets in an integer array. #include #include #include #include using namespace std;vector > findP( vector & x ) { set pool; vector > rel; if(x.size() < 3

2013-01-23 07:44:23 476

原创 A2: symmetric digits

integers of symmetric digitscoplexity: O(n)#include #include using namespace std;bool isSymetric( int x ) { char buff[32]; int i=0; while( x != 0){ buff[i++] = x%10; x/=10; } i

2013-01-23 06:28:39 351

原创 leetcode 47: subsets

Given a set of distinct integers, S, return all possible subsets.Note:Elements in a subset must be in non-descending order.The solution set must not contain duplicate subsets.F

2013-01-22 18:52:37 708

原创 leetcode 46: 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, where

2013-01-19 19:33:09 695

原创 leetcode 45: Permutations

Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].  class

2013-01-19 08:29:40 902

原创 leetcode 44: 4Sum

Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:E

2013-01-18 10:19:47 624

原创 leetcode 43: Set Matrix Zeroes

Given am xn matrix, if an element is 0, set its entire row and column to 0. Do it in place.uncompletedclass Solution {public:    void setZeroes(vector > &matrix) {        // Start

2013-01-18 09:36:46 1580

原创 leetcode 35: Search Insert Position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.

2013-01-18 07:48:54 503

原创 goog 1: check continuous array.

existing an array, check the longest continuous sub-array. what if the array has 5 million elements.class ArrayUtils { public: void checkContinue( int a[], n) { int max=-1; int count

2013-01-17 13:40:18 491

原创 leetcode 41: Reverse Linked List II

Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy the fol

2013-01-16 16:07:13 705

原创 leetcode 40: Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, t

2013-01-16 09:25:43 705

原创 leetcode 39: Remove Element

Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.c

2013-01-16 09:06:25 1094

原创 leetcode 38: Remove Duplicates from Sorted List II

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->1

2013-01-16 08:21:51 1127 1

原创 leetcode 37: Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once.For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. c++ improved v

2013-01-15 12:44:48 542

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除