自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(90)
  • 收藏
  • 关注

原创 java-Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,1]

2015-03-11 15:52:54 593

原创 Divide Two Integers

Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.思路1:看样只能用减法了,依次减去除数,TOTS,肯定超时。思路2:每次减去N倍的除数,结果也加上N次,因此我们需要将除数扩大N倍。int扩展成long防止

2015-03-05 12:43:22 451

原创 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:Element

2015-03-04 15:54:23 432

原创 3Sum Closest

Given 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 that each input would have exact

2015-03-04 14:44:42 446

原创 Regular Expression Matching

Implement regular expression matching with support for '.' and '*'.'.' Matches any single character.'*' Matches zero or more of the preceding element.The matching should cover the entire input

2015-01-22 16:46:31 479

原创 Median of Two Sorted Arrays

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)). 最后从medianof two sorted arrays中看到

2015-01-21 16:27:08 512

原创 Java-Integer to Roman

Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999. 将阿拉伯数字转换为罗马字符 建立一个二维数组来代表转换表 代码如下:public class Solution { public String intToR

2015-01-15 16:43:41 473

原创 Java-Roman to Integer

Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.将罗马数字转为阿拉伯数字 对应转换表如下:个位数举例I, 1 】II, 2】 III, 3】 IV, 4 】V, 5 】VI, 6】 VII, 7】 VIII,8 】IX,

2015-01-15 14:58:39 519

原创 Java-Largest Number

Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be very

2015-01-15 14:05:21 717

原创 Java-Compare Version Numbers

Compare two version numbers version1 and version1.If version1 > version2 return 1, if version1  version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and c

2015-01-13 17:30:02 682

原创 Java-Binary Search Tree Iterator

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() a

2015-01-13 13:41:20 594

原创 Java-Maximum Gap

Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.Return 0 if the array contains less than 2 elements.Y

2015-01-12 21:18:33 629

原创 Java-Intersection of Two Linked Lists

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: a1 → a2 ↘

2015-01-08 16:01:44 425

原创 Java-Majority Element

Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element al

2015-01-08 15:42:06 574

原创 Java-Excel Sheet Column Number

Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ...

2015-01-08 15:34:45 722

原创 Java-Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 本质就是将

2015-01-08 15:28:37 597

原创 Java-Factorial Trailing Zeroes

Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Credits:Special thanks to @ts for adding this problem and creating all

2015-01-07 20:20:56 917

原创 Java-Palindrome Partitioning

Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For example, given s = "aab",Return [ ["aa","b"]

2015-01-07 17:09:41 514

原创 java-Longest Consecutive Sequence

Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4, 200, 1, 3, 2],The longest consecutive elements sequence is [1, 2,

2015-01-07 16:04:34 518

原创 java-Sum Root to Leaf Numbers

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 total

2015-01-07 15:03:49 414

原创 JAVA-Linked List Cycle I&&Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space? 第一题要求是否有环 从图中可以看出 使用快慢指针 只要有环两者必定会相遇  另外从

2015-01-07 14:30:37 551

原创 Word Ladder

Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate word

2015-01-07 14:05:40 437

原创 Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get

2015-01-07 14:02:45 366

原创 Best Time to Buy and Sell Stock III

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:You may

2015-01-06 14:11:37 541

原创 Triangle

Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [

2015-01-04 16:52:48 475

原创 Pascal's Triangle II

Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].Note:Could you optimize your algorithm to use only O(k) extra space?与Pascal's Tr

2015-01-04 15:39:16 421

原创 Pascal's Triangle

Given numRows, generate the first numRows of Pascal's triangle.For example, given numRows = 5,Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Pascal的每一层以1开始和结束 并且自第二位起 其值

2015-01-04 14:52:13 370

原创 Populating Next Right Pointers in Each Node II

Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant

2015-01-04 12:57:07 738

原创 Populating Next Right Pointers in Each Node

Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.

2015-01-04 12:49:16 567

原创 Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1

2015-01-04 11:11:45 466

原创 Path Sum II

Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum.For example:Given the below binary tree and sum = 22, 5 / \

2014-12-30 20:04:24 477

原创 Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum

2014-12-30 17:05:17 513

原创 Minimum Depth of Binary Tree

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.返回最小路径值 只要对左右节点进行判断即可 若左右节点都为空  则直

2014-12-30 16:20:16 456

原创 Balanced Binary Tree

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 never diffe

2014-12-30 16:04:50 432

原创 Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.将增序链表转换为均衡的二叉查找树 与数组转换相同 找到链表的中间结点 作为树的根节点进行赋值  再将链表以中间节点为界 分为左右子链表 进行递归赋值 代码如下:publi

2014-12-30 15:49:50 390

原创 Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.将增序数组转换为左右均衡的二叉查找树 根据查找树的性质 左子树所有节点小于根节点值 右边都大于根节点值 子树也遵循此性质 所以只要取出增序数组的中间值作为根节点 再将左右子数组进行递归 代码如下:p

2014-12-30 15:09:01 473

原创 Binary Tree Level Order Traversal II

Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},

2014-12-30 14:41:31 457

原创 Construct Binary Tree from Inorder and Postorder Traversal

Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.还是重构树  与上一题相比  先序换成了后序  思路还是一样 代码如下:public class S

2014-12-30 14:11:39 465

原创 Construct Binary Tree from Preorder and Inorder Traversal

Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.给出树的中序和先序遍历 要求返回树  中序结果{1,2,5,4,3,6} 先序{4,2,1,5,3,6}根据先

2014-12-30 13:36:05 446

原创 Binary Tree Zigzag Level Order Traversal

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary

2014-12-29 20:58:52 301

空空如也

空空如也

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

TA关注的人

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