自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 53. Maximum Subarray

题目描述: Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4], the contiguous subarray [4,−1,2,1]

2016-04-22 18:15:03 278

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

2016-04-22 13:05:14 224

原创 343. Integer Break

问题描述: Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, r

2016-04-22 12:05:51 221

原创 260. Single Number III

问题描述: Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given nums

2016-04-21 22:57:53 228

原创 137. Single Number II

问题描述: Given an array of integers, every element appears three times except for one. Find that single one我的解决思路: 数组中的每个元素都出现三次,除了某个数,这里的这个数可能出现一次也可能出现两次,所以在后面的异或操作中应该写成(nums[i]^nums[i+2])!=0。java代码:pu

2016-04-21 22:33:29 190

原创 136. Single Number

问题描述: Given an array of integers, every element appears twice except for one. Find that single one.我的解决思路: 数组里的每个元素都出现两次除了某一个数,将数组排好序后,将相邻的两个数进行异或操作,相同的两个数异或结果为0。如果异或的结果不为0,则a[i]就是要找的那个数,不可能是a[i+1],注

2016-04-21 22:05:05 236

原创 111. 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.java代码:/** * Definition for a binar

2016-04-21 11:59:57 226

原创 119. 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?我的解决思路: 先画出二维数组看规

2016-04-21 10:43:22 332

原创 118.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]]我的解决思路: 第n行的元素个数为n,就想到了数字三角,可

2016-04-21 10:03:47 226

原创 58. Length of Last Word

问题描述: Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is def

2016-04-20 21:00:41 228

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

2016-04-20 20:24:34 179

原创 Contains Duplicate

217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return f

2016-04-20 16:40:03 203

原创 2. Add Two Numbers

问题描述: You 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 numbers and return it as

2016-04-20 15:18:30 204

原创 155. 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() – G

2016-04-20 13:11:57 188

原创 28. Implement strStr()

问题描述: Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.下面附代码:public class Solution { public int strStr(String haystack, S

2016-04-20 11:59:17 190

原创 1. Two Sum

问题描述: Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution.Example: Given nums = [2,

2016-04-20 11:34:25 242

原创 83. 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.我的解决思路: 用一个引用指向当前的节点,如果p

2016-04-20 10:04:09 192

原创 232. Implement Queue using Stacks

问题描述: Implement the following operations of a queue using stacks.push(x) – Push element x to the back of queue. pop() – Removes the element from in front of queue. peek() – Get the front element. e

2016-04-20 09:26:04 203

原创 24. Swap Nodes in Pairs

**问题描述: Given 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 constant spac

2016-04-20 08:43:05 221

原创 198. House Robber

**问题描述: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjace

2016-04-20 07:58:47 240

原创 202. Happy Number

**问题描述: Write an algorithm to determine if a number is “happy”. A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the s

2016-04-19 23:18:09 285

原创 283. Move Zeroes

问题描述: Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling you

2016-04-19 19:49:59 235

原创 21. Merge Two Sorted Lists

**问题描述: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.**我的思路:由于最近在复习归并排序,所以就采取了类似的方法,大牛勿喷,欢迎指点下面附上代码:/**

2016-04-19 19:41:02 203

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

2016-04-19 17:52:42 224

原创 171. Excel Sheet Column Number

**问题描述: Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 … Z -> 26 AA -> 27 AB -> 28** 自己

2016-04-19 17:24:12 241

原创 100. 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 and the nodes have the same value.**解决方法:用分治

2016-04-19 16:42:57 211

原创 283. Move Zeroes

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your

2016-04-19 16:02:02 218

原创 226. Invert Binary Tree

以下博客纯属上手,大牛们勿喷。 Invert a binary tree.4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Google: 90% of our engineers use the software you wrote

2016-04-19 15:48:34 206

空空如也

空空如也

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

TA关注的人

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