自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 (java)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

2016-01-15 15:54:37 271

原创 (java)Evaluate Reverse Polish Notation

Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2", "1",

2016-01-15 15:48:40 237

原创 (java)N-Queens

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.

2016-01-15 15:46:00 583

原创 (java)Combination Sum II

Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina

2016-01-15 15:40:11 211

原创 串匹配算法之Sunday算法

sunday算法据说是效率比KMP,BM都好的算法sunday算法的关注点与kmp算法不一样,sunday算法关注的是目标串匹配则好,如果不匹配,则看下一位是否在模式串中(因为当前已经失配,那么下一位肯定是要参与匹配的)如果下一位在模式串中有,则关于最右边的这位进行对齐(因为可能这个下一位在模式串中不止一个)下面模拟一下算法第一趟acaba

2016-01-09 20:58:16 596

原创 串匹配算法之KMP算法

KMP算法简介就不讲了,对于朴素的模式串匹配算法,发生失配时每次只能移动一个位置,然后再进行比较,而KMP算法可以根据模式串本身的性质,来决定向后跳几步下面我们用一个例子来说明next数组的计算公式是其实next数组还有一个简单的方法可以看出来就是看它前面的与第0位开始的重复多少个,比如上面的 j=2的时候 next[1]=0,且p[j-1]=b!=p[

2016-01-09 20:21:01 411

原创 (java)Combinations

Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]

2016-01-09 17:35:01 463

原创 (java)Range Sum Query - Immutable

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan

2016-01-08 11:52:15 278

原创 (java)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-01-08 11:44:01 323

原创 (java)Jump Game II

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.Your goal i

2016-01-08 11:34:44 318

原创 (java)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 i

2016-01-08 11:10:06 672

原创 (java)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

2016-01-08 10:52:33 197

原创 (java)First Bad Version

You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on the

2016-01-08 10:47:36 245

原创 (java)Summary Ranges

Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].思路:循环遍历这个数组,如果a[i+1]代码如下(已通过leetcode)public cla

2016-01-08 10:42:18 314

原创 (java)Count Primes

Count the number of prime numbers less than a non-negative number, n.思路:设置一个标志位数组flag[i],表示i是否已经被标记了。循环sqrt(n) 次,把i的倍数的全部标记上。最后没有标记的就是素数。比如n=15把2的倍数 4,6,8,10,12,14标记上把3的倍数 6 9,12;剩下的2,3,5,

2016-01-08 10:38:55 427

原创 (java)Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a

2016-01-08 10:23:36 342

原创 (java)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 on

2016-01-06 23:41:27 239

原创 (java)Best Time to Buy and Sell Stock

Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),

2016-01-06 23:31:35 205

原创 (java)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 

2016-01-06 20:49:17 292

原创 (java)Single Number

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

2016-01-06 20:40:10 347

原创 (java)Compare Version Numbers

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

2016-01-06 20:35:51 289

原创 (java)Rotate Array

Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].思路:本题的题意很容易理解,就是从右边数的k个数,移到数组的前面。注意:当数组的长度小于k

2016-01-06 20:30:59 550

原创 (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 思路:本题就是

2016-01-06 20:27:43 397

空空如也

空空如也

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

TA关注的人

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