- 浏览: 88797 次
最新评论
-
hcx2013:
mircle 写道Given nums = [1, 2, 1, ...
Single Number III -
mircle:
Given nums = [1, 2, 1, 3, 2, 5, ...
Single Number III -
hcx2013:
恩,可以,代码更简洁
空格替换 -
QuarterLifeForJava:
这样可以吗?
public static void main( ...
空格替换 -
hcx2013:
这个2是指多出2位,按你的理解可以这么改:int len = ...
空格替换
文章列表
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.
/**
* Definition for singly-linked list with a random pointer.
* class RandomListNode {
* int label;
* RandomListN ...
Permutations
- 博客分类:
- leetcode
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].
求1+2+3+...+n
- 博客分类:
- 剑指offer
求1+2+3+...+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字及条件判断语句(A?B:C)。
public class Solution {
private static int sum = 0;
public static boolean and(int n) {
sum += n;
return (n > 0) && and(n - 1);
}
public int Sum_Solution(int n) {
and ...
观察者模式是对象的行为模式,又叫发布-订阅(Publish/Subscribe)模式、模型-视图(Model/View)模式、源-监听器(Source/Listener)模式或从属者(Dependents)模式。
观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象。这个主题对象在状态上发生变化时,会通知所有观察者对象,使它们能够自动更新自己。
package cn.xidian.Design.Patterns;
import java.util.Observable;
import java.util.Observer;
...
Jump Game II
- 博客分类:
- leetcode
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 is to reach the last index in the minimum number of jumps.
For example:Given array A = [2,3,1,1,4]
The ...
Wildcard Matching
- 博客分类:
- leetcode
Implement wildcard pattern matching with support for '?' and '*'.
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
The function prototype should be:
bool isMatch(const ch ...
Multiply Strings
- 博客分类:
- leetcode
Given two numbers represented as strings, return multiplication of the numbers as a string.
Note: The numbers can be arbitrarily large and are non-negative.
public class Solution {
public String multiply(String num1, String num2) {
String st1 = new StringBuilder(num1).reverse().toStr ...
Trapping Rain Water
- 博客分类:
- leetcode
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], return 6.
The above elevation map is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, ...
Given an unsorted integer array, find the first missing positive integer.
For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.
Your algorithm should run in O(n) time and uses constant space.
public class Solution {
public int firstMissingPositive(int[] nums) {
int left = ...
Combination Sum II
- 博客分类:
- leetcode
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums toT.
Each number in C may only be used once in the combination.
Note:
All numbers (including target) will be positive integers.
Elements in a combination (a1, ...
package cn.xidian.edu.LIS;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class DoubleEndLIS {
public static void main(String[] args) {
int array[] = {1,4,5,3,2,1,4,5,6};
System.out.println(solve(array));
}
private static int solve(int[] ...
Combination Sum
- 博客分类:
- leetcode
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 number of times.
Note:
All numbers (including target) will be positive integers.
Elements in a combinat ...
Count and Say
- 博客分类:
- leetcode
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.
Sudoku Solver
- 博客分类:
- leetcode
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...
...and its solution numbers marked in red.
Valid Sudoku
- 博客分类:
- leetcode
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.
The Sudoku board could be partially filled, where empty cells are filled with the character '.'.
A partially filled sudoku which is valid.
Note:A valid Sudoku board (partially filled) is not necessarily solvable. Only ...