自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Copy List with Random Pointer

A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list. 思路一: 可以用一个哈希表来存储当前结点和新链表中对应结点的对应关系pub

2015-09-07 16:06:18 200

原创 Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string "23"O

2015-09-04 20:50:51 321

原创 HTTP Status 404 - No result defined for action cn.csdn.hr.s2sh.action.AdminAction and result success

警告: Could not find action or result No result defined for action cn.csdn.hr.s2sh.action.AdminAction and result success at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActi

2015-09-03 19:01:17 659

原创 Spring AOP问题

Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator#0’ d

2015-09-02 16:00:14 253

原创 Gas Station

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its nex

2015-08-30 21:35:31 268

原创 Permutations II

Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example, [1,1,2] have the following unique permutations: [1,1,2], [1,2,1], and [2,1,1].思路:考查的主

2015-08-29 11:49:32 318

原创 Edit Distance

Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a) In

2015-08-25 09:42:38 217

原创 Distinct Subsequences

Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of

2015-08-25 08:58:18 222

原创 Different Ways to Add Parentheses

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *. Example 1 Input

2015-08-22 09:54:21 203

原创 Pow(x, n)

public class Solution { public double myPow(double x, int n) { if(n<0) { if(n==-2147483648) return 1.0/(myPow(x,2147483647)*x); else return 1.0/myPow

2015-08-21 09:21:40 238

原创 Unique Binary Search Trees II

Given n, generate all structurally unique BST’s (binary search trees) that store values 1…n.For example, Given n = 3, your program should return all 5 unique BST’s shown below. 1 3 3

2015-08-20 08:24:55 233

原创 Lowest Common Ancestor of a Binary Tree

Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined between two nodes v and

2015-08-20 07:49:19 253

原创 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 / \

2015-08-19 16:32:36 343

原创 House Robber II

Note: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all

2015-08-19 15:03:14 226

原创 Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are

2015-08-19 13:40:29 252

原创 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"], ["a

2015-08-10 16:00:30 260

原创 Kth Largest Element in an Array

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example, Given [3,2,1,5,6,4] and k = 2, return 5.Note:

2015-08-09 13:30:29 270

原创 Binary Tree Right Side View

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example: Given the following binary tree, 1

2015-08-06 09:35:36 270

原创 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], [6,5,7],

2015-08-04 21:55:02 217

原创 Unique Paths II

Follow up for “Unique Paths”:Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the grid.For ex

2015-07-26 10:54:43 304

原创 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], ret

2015-07-24 16:35:26 373

原创 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 sum of al

2015-07-24 09:50:09 273

原创 Container With Most Water

Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lin

2015-07-23 21:30:23 325

原创 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 extra space.

2015-07-22 17:33:58 319

原创 Sliding Window Maximum

Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window mo

2015-07-22 10:11:12 309

原创 Set Matrix Zeroes

Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.思路:其实主要就是找出哪一行哪一列应该被设置为0,如果用两个list来记录哪些行和哪些列应该被设置为0,很容易就可以写出算法。但是题目要求空间复杂度为o(1),可利用以第一行和第一列来记录哪些行和哪些列应该被设置为0

2015-07-17 09:40:08 314

原创 Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place.For example,

2015-07-17 09:21:44 198

原创 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].思路:运用排列的思想。可以把数组转化为两部分,可

2015-07-14 20:48:57 274

原创 Rotate Image

You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up: Could you do this in-place?思路:先将矩阵转置,然后第一列和最后一列交换,第二列和倒数第二列交换,第三列和倒数第三列交换….直到第n/2列和倒数第n/2列交

2015-07-14 17:16:55 309

原创 Unique Paths

A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the botto

2015-07-13 10:05:23 262

原创 Single Number II

Given an array of integers, every element appears three times except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. Could you implement it without using ex

2015-07-12 20:20:45 298

原创 Binary Tree Postorder Traversal

Given a binary tree, return the postorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [3,2,1].思路:后序遍历是 左子树-根节点-右子树,递归的方式很简单,但是迭代的

2015-07-12 19:47:12 239

原创 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:“((()))”, “(()())”, “(())()”, “()(())”, “()()()”思路:看到这

2015-07-11 10:48:52 235

原创 Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.思路:刚刚开始的时候没有看到题目中说这个数组是升序的,就觉得很麻烦,既然数组是升序的,那就好办了,题目中说的是要转换为平衡的排序二叉树,要保证左右两边的高度相差不超过1,数组中间的那个数肯定是根结点,然后左子

2015-07-01 15:09:55 244

原创 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.

2015-06-29 09:35:32 246

原创 Unique Binary Search Trees

Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1 \ /

2015-06-26 17:01:06 336

原创 Binary Tree Inorder Traversal

Given a binary tree, return the inorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursive solution is trivial, could yo

2015-06-25 14:56:44 245

原创 java模拟linux命令scp

要导入包ganymed-ssh2-build210.jarpackage testScp; import java.io.IOException;import ch.ethz.ssh2.Connection; import ch.ethz.ssh2.SCPClient;public class Scp {/** * @param args */ public static voi

2015-06-25 10:32:33 803

原创 Binary Tree Preorder Traversal

Given a binary tree, return the preorder traversal of its nodes’ values.For example: Given binary tree {1,#,2,3}, 1 \ 2 / 3 return [1,2,3].思路:需要借助栈,由于是前序遍历二叉树,肯定是左子树先于右子树被访问,由

2015-06-25 10:29:07 372

原创 Best Time to Buy and Sell Stock II

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 as many transactions as you like (ie, buy one and

2015-06-24 15:04:27 324

空空如也

空空如也

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

TA关注的人

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