自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

popfish的算法路

Java, Algorithm, Coding

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

原创 Add, Subtract, Multiply numbers without using "+", "-", "*" operation

Approach the problem using bit manipulation.Add Number is the base operation for Subtract and Multiply.In binary representation, when adding two numbers, we can separate sum and carry procedur

2013-07-21 16:13:46 1337

原创 Leetcode 上和DP有关的题,不完整整理(目录)

把Leetcode上面几道和DP有关的题整理了一下放到一起,先Po出一部分,剩下有时间放上来DP比较常用的就是利用数组和矩阵Cache了,有很多经典的题是和String结合的,所以要明白用矩阵表示String的含义我们先从矩阵的看起,下面四个题比较简单,题目的背景就是矩阵,写在一个帖子里先来热热身。Unique Path I & II,Minimum Path Su

2013-07-07 11:24:04 10308 1

原创 Leetcode上几道Binary Search题需要注意的地方

Binary Search的原理很容易理解,但是每次脚标没算对弄得溢出或是死循环的时候总是很恼火。今天就把Leetcode上几道经典的利用Binary Search解的题放在一起来感受一下。一般有几个比较容易迷糊的地方,·1. 终止条件不同 是取 start  2. 分半的时候是取mid, mid - 1, 还是mid + 1 (这里mid含义对应数组的index, 如果涉及到

2013-06-30 17:10:38 3611

原创 Leetcode上和DFS有关题目整理 (内含目录)

总结一下Leetcode上一些比较经典的利用dfs思路解的题:按照顺序排了一下,如果从第一道题一直做到最后一道题,会对dfs有一个新的认识。我们从最典型的开始,首先是关于数字集合的问题,例如输出所有子集,所有序列,我们把这些题当作dfs的基础。Subset I, IICombinationPermutation I, IICombination Co

2013-06-24 08:07:00 43407 1

原创 Find Longest Unrepeated Letters in Cyclic Linked-List

无聊在版上闲逛发现Po出来一个题,自己试着写一下。Find Longest Unrepeated Letters Length in Cyclic Linked-List (The List only Contain Upper letter from 'A' - 'Z')For Example: ...A(head)-B-C-A-B-C-B-D-A(head)..... The Link

2013-07-11 16:09:08 1184

原创 Fibonacci Number Generator

在版上看到的一道题:写一个fibonacci数的生成器,每次调用生成下一个fibonacci数例如,第一次调用getNext()生成0,第二次调用getNext()生成1,第三次调用getNext()生成1,第四次调用getNext()生成2。。。。还要求有一个reset()来归0本来想用fib数的公式fib(n) = fib(n-1) + fib(n-2) 维持一个数组在类里面,

2013-07-09 03:23:21 1276

原创 Leetcode: Decode Ways

Problem: Decode WaysA message containing letters from A-Z is being encoded to numbers using the following mapping:'A' -> 1'B' -> 2...'Z' -> 26Given an encoded message containing digi

2013-07-07 11:23:51 6024 1

原创 Leetcode: Distinct Subsequences

Problem: Distinct SubsequencesGiven 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 origin

2013-07-07 11:23:38 2389 1

原创 Leetcode: Edit Distance

Problem 7: Edit DistanceGiven 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

2013-07-07 11:23:20 2152

原创 Leetcode: Interleaving String

Problem: Interleaving StringGiven s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", ret

2013-07-07 11:23:01 11806 8

原创 Leetcode: Unique Path I & II, Minimum Path Sum, Triangle

这四个题都是比较直观的DP题,题目中已经暗示了我们怎么Cache递归表达式算出来的数据,我们可以采取和题目中一样的矩阵,或者节省一部分空间采用滚动数组解题Problem 1: Unique Path IA robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram

2013-07-07 11:22:33 3189 1

原创 Po一道有意思的题

今天朋友做一家公司发过来的面试题,有一道小题虽然简单但还蛮好玩的,记录下来。A non-empty zero-indexed array A consisting of N integers is given. The array consists only of integers in the range [0..N−1]. Each element of the array

2013-07-07 06:43:58 3981

原创 Leetcode Maximum SubArray & Binary Tree Maximum Path Sum

发现这两道题运用了同一个思路,把它们放到一起Problem: 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,−

2013-07-02 03:31:58 2918 3

原创 Leetcode: Palindrome Partitioning I & II

Problem I : Palindrome Partitioning I Given a string s, partition s such that every substring of the partition is a palindrome.Return all possible palindrome partitioning of s.For exam

2013-06-26 14:08:36 5603 2

原创 Leetcode Word Search

Given 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 those horizontally or vertically

2013-06-24 13:18:22 2908 1

原创 Leetcode Sudoku Solver

Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution.A sudoku puzzle...

2013-06-24 08:35:21 5468 3

原创 Leetcode: N Queen I & II

The n-queens puzzle is the problem of placing n queens on an n�n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle. Each

2013-06-24 08:33:15 8532 2

原创 Leetcode Surrounded Regions

Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region .For example,X X X XX O O XX

2013-06-24 08:30:25 3576 4

原创 Leetcode Restore IP Address

Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example: Given "25525511135", return ["255.255.11.135", "255.255.111.35"].(Order d

2013-06-24 08:26:37 11064 3

原创 Leetcode: Combination 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

2013-06-24 08:24:52 2712

原创 Leetcode 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-06-24 08:23:13 4901 1

原创 Leetcode Combination Sum I & II

Problem 1: Combination Sum IGiven 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 c

2013-06-24 08:20:15 3982 1

原创 Leetcode Permutation I & II

Problem 1: Permutation IGiven 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 [

2013-06-24 08:14:59 5305 1

原创 Leetcode Subset I & II

Problem 1: Subset IGiven 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 subs

2013-06-24 08:10:13 18833 4

空空如也

空空如也

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

TA关注的人

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