- 博客(81)
- 收藏
- 关注
原创 leetcode148套题
只刷剑指不行,宝宝我还要刷点别的,啊啊啊,实习了一天头好疼,但是不行,我要坚持坚持坚持!1、树: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
2017-09-06 22:55:31
477
原创 剑指offer
艾瑞巴蒂,我来刷剑指了,因为要找工作了呀~ ^_^ 紧急紧急!!!这里来记录下~1、二维数组的查找:题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。思路:从右上角开始,比目标大的话往左走;比目标小的话,向下走。源码:public class Solution
2017-09-06 22:47:29
522
原创 剑指offer刷刷题
1、编程实现设计模式:Singleton(单例模式)public class Singleton{ private Singleton(){} private static Singleton s = new Singleton(); public static Singleton getSingleton() { return s; }}
2017-07-18 22:35:15
737
原创 Leetcode刷题记——50. Pow(x, n)
一、题目叙述:Implement pow(x, n).二、解题思路:Medium题。&参考。思路:递归实现,注意n为负时,不能用 1 / mypow(x, -n)。三、源码:public class Solution { public double m
2017-04-13 23:08:19
349
原创 Leetcode刷题记—— 4. Median of Two Sorted Arrays(两有序数组的中位数)
一、题目叙述:There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity sh
2017-04-12 20:02:32
385
原创 背景
一、B-树:public class BTreeSET >{ private Page root = new Page(true); public BTreeSET(Key sentinel) { add(sentinel); } public boolean contains(Key key) { return contains(root, key); } priv
2017-04-10 11:11:07
290
1
原创 数据压缩
一、Huffman压缩:public class Huffman { private static int R = 256; private static class Node implements Comparable { private Node left, right; private int freq; private char ch; Node(char ch
2017-04-08 10:55:41
276
原创 正则表达式
一、NFA的构造与匹配:public class NFA { private int M; private Digraph G; private char[] re; public NFA(String regexp) { Stack ops = new Stack(); M = regexp.length(); G = new Digraph(M+1); re
2017-04-07 10:47:49
248
原创 子字符串查找
一、暴力子字符串查找算法:public class Baoli { public static int search(String pattern, String txt) { int M = pattern.length(); int N = txt.length(); for (int i = 0; i < N-M; i++) { int j; for (
2017-04-06 11:37:23
266
原创 单词查找树
一、基于单词查找树的符号表:public class TrieST{ private Node root; private static int R = 256; private static class Node { private Object val; private Node[] next = new Node[R]; } public Value get(Str
2017-04-05 21:23:01
330
原创 字符串排序
一、低位优先字符串排序算法(LSD):public class LSD{ public static void sort(String[] a, int W) { int R = 256; int N = a.length; int[] count = new int[R+1]; String[] aux = new String[N]; for (int d = W
2017-03-30 11:41:10
371
原创 图
一、无向图Graph数据类型:import java.util.Scanner;public class Graph{ private final int V; private int E; private Bag[] adj; public Graph(int v) { this.V = v; this.E = 0; adj = (Bag[])new Bag[
2017-03-20 18:28:50
301
原创 Leetcode刷题记—— 46. Permutations(排列)
一、题目叙述:Given a collection of distinct numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[ [1,2,3], [1,3,2]
2017-03-13 20:18:22
267
原创 符号表
一、无序链表的顺序查找:import java.util.ArrayList;import java.util.Iterator;public class SequentialSearchST{ private Node first; private int N; private class Node { Key key; Value val; Node next
2017-03-07 11:16:01
294
原创 Leetcode刷题记—— 60. Permutation Sequence(排列序列)
一、题目叙述:The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie
2017-03-05 16:48:12
499
原创 Leetcode刷题记—— 73. Set Matrix Zeroes(设置矩阵0)
一、题目叙述:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.click to show follow up.Subscribe to see which companies ask
2017-03-05 11:04:08
744
原创 Leetcode刷题记—— Remove Duplicates from Sorted Array II(已排序数组移除重复元素2)
一、题目叙述:Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should retur
2017-03-04 17:48:51
401
原创 Leetcode刷题记——75. Sort Colors(颜色排序)
一、题目叙述:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
2017-03-04 17:23:58
481
原创 Leetcode刷题记——100. Same Tree(相同的树)
一、题目叙述: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 imp
2017-03-03 19:27:51
312
原创 Leetcode刷题记——29. Divide Two Integers(整数相除Divide two integers without using multiplication, division)
一、题目叙述:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.两整数相除,不能使用乘法,除法和取模运算。二、解题思路:Medium题,不能用乘除取模,那
2017-03-03 18:57:20
325
原创 Leetcode刷题记——136. 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 imp
2017-02-28 16:41:58
268
原创 Leetcode刷题记——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.
2017-02-28 15:06:35
396
原创 优先队列
一、基于堆的优先队列:public class MaxPQ>{ private int N = 0; private Key[] pq; public MaxPQ(int maxN) { pq = (Key[])new Comparable[maxN+1]; } public boolean isEmpty() { return N == 0; } publ
2017-02-28 11:33:28
222
原创 Leetcode刷题记——147. Insertion Sort List(插入排序链表)
一、题目叙述:Sort a linked list using insertion sort.二、解题思路:Medium题,啊。。。我今天头晕脑胀,写的不太顺利。代码之混乱,我现在提交成功了都还很迷。使用插入排序的方法对链表进行排序,即每次和前面的结点比找到合适的位置插入,链表不同于数组的地方在于,只能从前往后比,找到第一个比目前结点值大的结点,
2017-02-27 18:52:46
508
原创 Leetcode刷题记——70. Climbing Stairs(爬楼梯)
一、题目叙述:You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Giv
2017-02-27 17:33:24
742
原创 归并排序、快速排序、堆排序
一、自顶向下的归并排序:public class Merge{ private static Comparable[] aux; public static void merge(Comparable[] a, int lo, int mid, int hi) { //aux = new Comparable[a.length]; for (int k = lo; k <= h
2017-02-27 16:22:25
201
原创 Leetcode刷题记——48. Rotate Image(旋转图像)
一、题目叙述:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?Subscribe to see which companies
2017-02-26 17:18:07
525
原创 Leetcode刷题记——67. Add Binary(二进制数相加)
一、题目叙述:Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".Subscribe to see which companies asked this q
2017-02-26 16:42:51
351
原创 初级排序算法实现
一、选择排序:public class Selection { public static void sort(Comparable[] a) { int N = a.length; for (int i = 0; i < N; i++) { int min = i; for (int j = i + 1; j < N; j++) if (less(a[j
2017-02-26 11:15:51
265
原创 Leetcode刷题记——59. Spiral Matrix II(螺旋矩阵2)
一、题目叙述:Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [
2017-02-25 20:02:43
510
原创 Leetcode刷题记——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, r
2017-02-25 19:34:35
705
原创 union-find算法
一、quick-find:import java.util.Scanner;public class UF //quick-find{ private int[] id; private int count; public UF(int N) { count = N; id = new int[N]; for (int i = 0; i < N; i++)
2017-02-25 19:17:41
296
原创 Leetcode刷题记——54. Spiral Matrix(螺旋矩阵)
一、题目叙述:Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6
2017-02-23 19:00:37
792
原创 Leetcode刷题记——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
2017-02-23 17:24:42
269
原创 Leetcode刷题记——41. First Missing Positive(第一个丢失的正数)
一、题目叙述: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) tim
2017-02-22 21:19:27
360
原创 Leetcode刷题记——88. Merge Sorted Array(合并有序数组)
一、题目叙述:Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal to m + n
2017-02-22 20:17:52
298
原创 Leetcode刷题记——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
2017-02-21 18:39:36
344
原创 Leetcode刷题记—— 84. Largest Rectangle in Histogram(柱形图中最大矩形面积)
一、题目叙述:Given n non-negative integers representing the histogram's bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is a histogra
2017-02-21 18:05:04
427
原创 背包、队列、栈
一、定容栈public class FixedCapacityStackOfStrings { private String[] a; private int N; public FixedCapacityStackOfStrings(int cap) { a = new String[cap]; } public void push(String item) { a
2017-02-21 16:04:14
250
原创 Leetcode刷题记—— 66. Plus One(加1)
一、题目叙述:Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not co
2017-02-07 23:07:07
1503
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人