- 博客(34)
- 资源 (1)
- 收藏
- 关注
原创 [Lintcode]Minimum Size Subarray Sum 和大于S的最小子数组
Given an array of n positive integers and a positive integer s, find the minimal length of a subarray of which the sum ≥ s. If there isn't one, return -1 instead.ExampleGiven the array [2,3,1,
2016-11-27 18:00:37 283
原创 [Lintcode]Maximum Subarray II 最大子数组 II
Given an array of integers, find two non-overlapping subarrays which have the largest sum.The number in each subarray should be contiguous.Return the largest sum.ExampleFor given [1, 3, -1,
2016-11-27 16:23:02 356
原创 ***[Lintcode]Maximum Subarray Difference 最大子数组差
Given an array with integers.Find two non-overlapping subarrays A and B, which |SUM(A) - SUM(B)| is the largest.Return the largest difference.ExampleFor [1, 2, -3, 1], return 6.分
2016-11-27 15:55:28 366
原创 **[Lintcode]Maximal Square 最大正方形
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and return its area.ExampleFor example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11
2016-11-27 10:21:08 368
原创 [Lintcode]Binary Tree Level Order Traversal II 二叉树的层次遍历 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).ExampleGiven binary tree {3,9,20,#,#,15,7},
2016-11-23 22:45:27 455
原创 *[Lintcode]k Sum II
Given n unique integers, number k (1Find all possible k integers where their sum is target.ExampleGiven [1,2,3,4], k = 2, target = 5. Return:[ [1,4], [2,3]]分析:递归
2016-11-20 18:11:48 260
原创 **[Lintcode]Subarray Sum Closest最接近零的子数组和
Given an integer array, find a subarray with sum closest to zero. Return the indexes of the first number and last number.ExampleGiven [-3, 1, 1, -3, 5], return [0, 2], [1, 3], [1, 1], [2,
2016-11-20 16:16:42 595
原创 [Lintcode] Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n^2 in spiral order.ExampleGiven n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2016-11-20 14:33:39 258
原创 **[Lintcode]Unique Binary Search Trees II 不同的二叉查找树 II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.ExampleGiven n = 3, your program should return all 5 unique BST's shown below. 1 3
2016-11-19 15:37:10 277
原创 **[Lintcode]Permutation Sequence 第k个排列
Given n and k, return the k-th permutation sequence.ExampleFor n = 3, all permutations are listed as follows:"123""132""213""231""312""321"If k = 4, the fourth permutation is "
2016-11-19 14:26:32 264
原创 **[Lintcode]Word Break单词切分
Given a string s and a dictionary of words dict, determine if s can be break into a space-separated sequence of one or more dictionary words.ExampleGiven s = "lintcode", dict = ["lint", "cod
2016-11-18 11:25:44 528
原创 *[Lintcode]Unique Binary Search Trees 不同的二叉查找树
Given n, how many structurally unique BSTs (binary search trees) that store values 1...n?ExampleGiven n = 3, there are a total of 5 unique BST's.1 3 3 2 1 \
2016-11-17 16:42:17 198
原创 *[Lintcode]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
2016-11-17 15:15:27 316
原创 **[Lintcode]Validate Binary Search Tree 验证二叉查找树
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2016-11-17 14:54:53 247
原创 ***[Lintcode]Word Ladder 单词接龙
Given two words (start and end), and a dictionary, find the length of shortest transformation sequence from start to end, such that:Only one letter can be changed at a timeEach intermediate
2016-11-16 16:01:32 703
原创 **[Lintcode]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.ExampleGiven [0,1,0,2,1,0,1,3,2,1,2,1]
2016-11-16 10:45:37 251
原创 *[Lintcode]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, w
2016-11-15 17:36:07 274
原创 [Lintcode]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.ExampleX X X XX O O XX X
2016-11-15 16:01:27 203
原创 *[Lintcode]Subsets 子集
Given a set of distinct integers, return all possible subsets.ExampleIf S = [1,2,3], a solution is:[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], []]分析:先排序,然后和求全排列算法
2016-11-15 14:07:18 242
原创 *[Lintcode]Spiral Matrix螺旋矩阵
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.ExampleGiven the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]
2016-11-15 10:56:48 249
原创 [Lintcode]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.Here, we will use the integers
2016-11-14 22:48:48 302
原创 Spring Boot 源码分析
在Spring Boot框架中,最先接触的应该就是SpringApplication这个类。所以源码分析也先从这个类开始。SpringApplication用来从Java的main方法中启动Spring Boot应用。他的行为包括:创建适当的应用上下文实例对应CommandLinePropertySource和Spring的参数初始化应用上下文,并且加载单例Bean触发Comman
2016-11-14 16:02:51 3924
原创 ***[Lintcode]Single Number II 落单的数 II
Given 3*n + 1 numbers, every numbers occurs triple times except one, find it.ExampleGiven [1,1,2,3,3,3,2,2,4,1] return 4分析:int型需要32位表示。因此对于每一位,计算数组中所有数组在该位的和mod3. 但是不满足one-pass要求pu
2016-11-13 17:30:46 225
原创 [Lintcode] Search in Rotated Sorted Array II 搜索旋转排序数组 II
Follow up for Search in Rotated Sorted Array:What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the
2016-11-13 16:10:24 270
原创 *[Lintcode]Simplify Path简化路径
Given an absolute path for a file (Unix-style), simplify it.Example"/home/", => "/home""/a/./b/../../c/", => "/c"分析:用stack,先将路径split,得到的数组有几种字符需要处理 ".":代表当前目录,忽略 "../":代表上一级目录,出栈, 其他:代表路径
2016-11-13 11:12:01 1199
原创 [Lintcode] Set Matrix Zeroes矩阵归零
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place.ExampleGiven a matrix[ [1,2], [0,3]],return[[0,2],[0,0]]分析:为了节约空间,可以使用第一行/第一列
2016-11-13 10:03:04 367
原创 *[Lintcode]搜索旋转排序数组
Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array retur
2016-11-12 18:36:33 240
原创 [Lintcode]Search for a Range搜索区间
Given a sorted array of n integers, find the starting and ending position of a given target value.If the target is not found in the array, return [-1, -1].ExampleGiven [5, 7, 7, 8, 8, 10]
2016-11-12 17:02:40 194
原创 [Lintcode] Search a 2D Matrix II搜索二维矩阵 II
Write an efficient algorithm that searches for a value in an m x n matrix, return the occurrence of it.This matrix has the following properties:Integers in each row are sorted from left to rig
2016-11-12 16:21:09 321
原创 [Lintcode]Rotate List旋转链表
Given a list, rotate the list to the right by k places, where k is non-negative.ExampleGiven 1->2->3->4->5 and k = 2, return 4->5->1->2->3./** * Definition for singly-linked list. *
2016-11-12 15:38:43 179
原创 [Lintcode]Reverse Linked List II 翻转链表 II
Reverse a linked list from position m to n.ExampleGiven 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL.分析:实现题。双指针。/** * Definition for ListNode * public class
2016-11-10 17:12:22 245
原创 [Lintcode]Reorder List 重排链表
Given a singly linked list L: L0 → L1 → … → Ln-1 → Lnreorder it to: L0 → Ln → L1 → Ln-1 → L2 → Ln-2 → …分析:先是用快慢指针找到中间点。然后从中间点开始生成一个后半段的倒序的list。然后插空合并L: L0 → L1 → … → Lk
2016-11-10 15:36:15 262
原创 [Lintcode]Remove Duplicates from Sorted List II 删除排序链表中的重复数字 II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.ExampleGiven 1->2->3->3->4->4->5, return 1->2->5.Given 1->1->
2016-11-10 11:01:26 227
原创 ***[Lintcode]Permutations II 带重复元素的排列 递归/非递归解法
Given a list of numbers with duplicate number in it. Find all unique permutations.ExampleFor numbers [1,2,2] the unique permutations are:[ [1,2,2], [2,1,2], [2,2,1]]分析:可以使用递归。设置一个
2016-11-08 16:11:50 697
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人