算法-Array
大大kc
今日事,今日毕
展开
-
leetcode54. Spiral Matrix
54. Spiral MatrixGiven 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 ], [ 7,原创 2017-06-21 23:44:56 · 197 阅读 · 0 评论 -
leetcode628. Maximum Product of Three Numbers
628. Maximum Product of Three NumbersGiven an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]O原创 2017-06-25 17:52:40 · 1185 阅读 · 0 评论 -
leetcode624. Maximum Distance in Arrays
624. Maximum Distance in ArraysGiven m arrays, and each array is sorted in ascending order. Now you can pick up two integers from two different arrays (each array picks one) and calculate the distance.原创 2017-06-25 17:29:18 · 498 阅读 · 0 评论 -
leetcode523. Continuous Subarray Sum
523. Continuous Subarray SumGiven a list of non-negative numbers and a target integer k, write a function to check if the array has a continuous subarray of size at least 2 that sums up to the multiple原创 2017-06-25 15:35:13 · 315 阅读 · 0 评论 -
leetcode560. Subarray Sum Equals K
560. Subarray Sum Equals KGiven an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k.Example 1: Input:nums = [1,1,1], k = 2 Output: 2原创 2017-06-25 14:03:03 · 594 阅读 · 0 评论 -
leetcode381. Insert Delete GetRandom O(1) - Duplicates allowed
381. Insert Delete GetRandom O(1) - Duplicates allowedDesign a data structure that supports all following operations in average O(1) time.Note: Duplicate elements are allowed. insert(val): Inserts an原创 2017-06-24 22:08:06 · 228 阅读 · 0 评论 -
leetcode380. Insert Delete GetRandom O(1)
380. Insert Delete GetRandom O(1)Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the set if not already present. remove(val): Re原创 2017-06-24 18:46:44 · 271 阅读 · 0 评论 -
leetcode238. Product of Array Except Self
238. Product of Array Except SelfGiven an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it w原创 2017-06-24 17:54:36 · 177 阅读 · 0 评论 -
leetcode228. Summary Ranges
228. Summary RangesGiven 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”].解法public class Solution { public Li原创 2017-06-22 23:01:05 · 266 阅读 · 0 评论 -
leetcode209. Minimum Size Subarray Sum
209. Minimum Size Subarray SumGiven an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 instead原创 2017-06-22 22:15:40 · 257 阅读 · 0 评论 -
leetcode106. Construct Binary Tree from Inorder and Postorder Traversal
106. Construct Binary Tree from Inorder and Postorder TraversalGiven inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.原创 2017-06-22 21:38:18 · 212 阅读 · 0 评论 -
leetcode105. Construct Binary Tree from Preorder and Inorder Traversal
105. Construct Binary Tree from Preorder and Inorder TraversalGiven preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.解法原创 2017-06-22 20:47:30 · 303 阅读 · 0 评论 -
leetcode79. Word Search
79. Word SearchGiven 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原创 2017-06-22 20:02:44 · 210 阅读 · 0 评论 -
leetcode59. Spiral Matrix II
59. Spiral Matrix IIGiven 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:[ [ 1, 2, 3 ], [ 8,原创 2017-06-21 23:55:21 · 209 阅读 · 0 评论 -
leetcode611. Valid Triangle Number
611. Valid Triangle NumberGiven an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of原创 2017-06-25 16:12:15 · 372 阅读 · 0 评论