自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

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

原创 【LeetCode】【JAVA】【085】Isomorphic Strings

题目:https://leetcode.com/problems/isomorphic-strings/思路:题目要求 s 到 t 不能同时 map 两个,t 到 s 也不可以。但两个映射是独立的。第一次用两个HashMap做,第二次用一个HashMap 一个 HashSet ,HashSet 用来检测重复。两种方法耗时一样。Code: public

2015-04-30 08:58:29 193

原创 【LeetCode】【JAVA】【085】Word Break II

题目:https://leetcode.com/problems/word-break-ii/思路:直接用 Recursion超时。取 Word Break 的思路,先 DP 获得 jth 位置可达到的 index,再通过 Recursion 获得所有结果。Code:public class Solution { ArrayList resAL;

2015-04-29 23:29:34 178

原创 【LeetCode】【JAVA】【084】Remove Linked List Elements

题目:https://leetcode.com/problems/number-of-1-bits/思路:NothingCode: public ListNode removeElements(ListNode head, int val) { while(head != null && head.val==val){

2015-04-29 22:31:13 184

原创 【LeetCode】【JAVA】【083】Happy Number

题目: https://leetcode.com/problems/happy-number/思路:用 HashSet 检查重复。另外有地方在讨论 Code: public boolean isHappy(int n) { if(n==1) return true; HashSet hs = new HashSet();

2015-04-29 22:06:02 184

原创 【LeetCode】【JAVA】【082】Number of 1 Bits

题目:https://leetcode.com/problems/number-of-1-bits/思路:n = n&(n-1) 可去除最右边的1,直到 n=0Code: public int hammingWeight(int n) { if(n==0) return 0; int res =0; whil

2015-04-29 04:44:17 141

原创 【LeetCode】【JAVA】【081】Word Break

题目:http://oj.leetcode.com/problems/word-break/思路:DP,res[i] 的 boolean 数组记录第 ith 位可否被 break。res[ j ] && wordDict.contains( s.substring( j , i+1 )) 判断第 ith 位可否被 break。遍历检测,知道 string 的最后一位。参考:ht

2015-04-29 03:28:39 170

原创 【iOS】【Swift】Swift and Objective-C in the Same Project | OC 转 Swift 的各种问题

1. 在Swift Project 下建一个 .h 文件2. 在 header 文件里用 OC import 要用到的 header 文件3. 在Build Setting 里的 Swift Compiler 里设 header 文件为 Bridge HeaderReference: https://developer.apple.com/library/ios/documen

2015-04-04 03:07:47 168

原创 【LeetCode】【JAVA】【080】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,

2015-04-03 11:37:35 149

原创 【LeetCode】【JAVA】【079】Pow(x, n)

题目:Implement pow(x, n).思路:使用二分法:pow(x,n) = pow(x,n/2)*pow(x,n-n/2)Code: public double pow(double x, int n) { if(n<0){ if( n == Integer.MIN_VALUE)

2015-04-03 10:56:42 214

原创 【LeetCode】【JAVA】【078】Valid Parentheses

题目:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all val

2015-04-03 10:19:31 139

原创 【LeetCode】【JAVA】【077】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-04-03 09:42:14 162

原创 【LeetCode】【JAVA】【076】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 ex

2015-04-03 08:43:46 170

原创 【LeetCode】【JAVA】【075】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-04-03 02:03:53 136

原创 【LeetCode】【JAVA】【074】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 adjacent

2015-04-02 10:28:33 340

原创 【LeetCode】【JAVA】【073】Reverse Bits

题目:Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 001110

2015-03-27 00:14:07 263

原创 【LeetCode】【JAVA】【072】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.Determ

2015-03-26 23:55:19 159

原创 【LeetCode】【JAVA】【071】Partition List

题目:Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each

2015-03-26 23:10:05 133

原创 【LeetCode】【JAVA】【070】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

2015-03-26 14:23:05 129

原创 【LeetCode】【JAVA】【069】Combination Sum

题目:Given 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 must not contain

2015-03-26 13:19:13 134

原创 【LeetCode】【JAVA】【068】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-03-26 09:34:53 141

原创 【LeetCode】【JAVA】【068】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-03-26 09:31:50 71

原创 【LeetCode】【JAVA】【067】Submission Details

题目:Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.思路:末尾的0 都由 2*5 得,2的数目比5的多,所以计算5的数目就可以。具体看:http://www.cnbl

2015-03-26 08:57:28 150

原创 【LeetCode】【JAVA】【066】Search for a Range

题目:Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found

2015-03-26 08:33:05 123

原创 【LeetCode】【JAVA】【065】Combination Sum

题目:Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited num

2015-03-24 23:53:04 208

原创 【LeetCode】【JAVA】【064】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

2015-03-24 13:51:56 140

原创 【LeetCode】【JAVA】【063】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 g

2015-03-24 12:57:17 128

原创 【LeetCode】【JAVA】【062】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.For example,

2015-03-24 12:11:29 167

原创 【LeetCode】【JAVA】【061】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

2015-03-24 11:31:14 197

原创 【LeetCode】【JAVA】【060】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:

2015-03-24 09:33:12 131

原创 【LeetCode】【JAVA】【059】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(

2015-03-23 22:39:35 175

原创 【LeetCode】【JAVA】【058】Palindrome Number

题目:Determine whether an integer is a palindrome. Do this without extra space.思路:做太多Array List,都忘了怎么处理 Int基本上就是 取余数,除10,还有求 Int 数的位数Code: public boolean isPalindrome(int x) {

2015-02-26 02:20:54 136

原创 【LeetCode】【JAVA】【057】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 [

2015-02-26 01:50:06 154

原创 【LeetCode】【JAVA】【056】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.思路:DFS,Recursion

2015-02-25 05:06:42 149

原创 【LeetCode】【JAVA】【055】Binary Tree Level Order Traversal

题目:Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20

2015-02-25 04:48:35 152

原创 【LeetCode】【JAVA】【054】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?

2015-02-25 04:28:47 142

原创 【LeetCode】【JAVA】【053】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

2015-02-24 09:02:20 168

原创 【LeetCode】【JAVA】【052】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 a

2015-02-24 07:48:35 157

原创 【LeetCode】【JAVA】【051】Merge Sorted Array

题目:Given two sorted integer arrays A and B, merge B into A as one sorted array.Note:You may assume that A has enough space (size that is greater or equal to m + n) to hold additional element

2015-02-24 07:20:11 217

原创 【LeetCode】【JAVA】【050】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-02-24 06:57:27 129

原创 【LeetCode】【JAVA】【049】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

2015-02-24 04:26:08 133

空空如也

空空如也

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

TA关注的人

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