随笔分类 -  Leetcode | Array

摘要:Problem IWrite a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. ... 阅读全文
posted @ 2015-08-19 16:03 Chapter 阅读(190) 评论(0) 推荐(0)
摘要:问题描述Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm shoul... 阅读全文
posted @ 2015-08-09 11:08 Chapter 阅读(128) 评论(0) 推荐(0)
摘要:Best Time to Buy and Sell Stock ISay you have an array for which theithelement is the price of a given stock on dayi.If you were only permitted to com... 阅读全文
posted @ 2015-08-09 10:46 Chapter 阅读(145) 评论(0) 推荐(0)
摘要:问题描述Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example,Given [100, 4, 200, 1, 3, 2],The lo... 阅读全文
posted @ 2015-08-04 11:10 Chapter 阅读(140) 评论(0) 推荐(0)
摘要:问题描述Given a set ofnon-overlappingintervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initi... 阅读全文
posted @ 2015-07-31 11:03 Chapter 阅读(164) 评论(0) 推荐(0)
摘要:问题描述Givennnon-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after rainin... 阅读全文
posted @ 2015-07-31 10:05 Chapter 阅读(138) 评论(0) 推荐(0)
摘要:问题描述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?解决思路难点在于,如何... 阅读全文
posted @ 2015-07-29 09:49 Chapter 阅读(138) 评论(0) 推荐(0)
摘要:问题描述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 r... 阅读全文
posted @ 2015-07-29 09:22 Chapter 阅读(179) 评论(0) 推荐(0)
摘要:问题描述Given amxnmatrix, if an element is 0, set its entire row and column to 0. Do it in place.解决思路难点在于如何不使用辅助空间。一个巧妙的想法是,1. 使用两个标记变量,row0_has_zeros和col... 阅读全文
posted @ 2015-07-25 10:49 Chapter 阅读(164) 评论(0) 推荐(0)
摘要:问题描述Given an arraySofnintegers, find three integers inSsuch that the sum is closest to a given number, target. Return the sum of the three integers. Y... 阅读全文
posted @ 2015-07-25 10:22 Chapter 阅读(122) 评论(0) 推荐(0)
摘要:问题描述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:[ ... 阅读全文
posted @ 2015-07-24 09:59 Chapter 阅读(112) 评论(0) 推荐(0)
摘要:问题描述Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit i... 阅读全文
posted @ 2015-07-24 08:52 Chapter 阅读(131) 评论(0) 推荐(0)
摘要:问题描述Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't... 阅读全文
posted @ 2015-07-24 08:33 Chapter 阅读(145) 评论(0) 推荐(0)
摘要:问题描述Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorte... 阅读全文
posted @ 2015-07-23 14:54 Chapter 阅读(113) 评论(0) 推荐(0)
摘要:问题描述Given an arraynums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumb... 阅读全文
posted @ 2015-07-19 10:50 Chapter 阅读(213) 评论(0) 推荐(0)
摘要:问题描述Given 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 exc... 阅读全文
posted @ 2015-07-16 10:30 Chapter 阅读(738) 评论(0) 推荐(0)
摘要:问题描述给定两个有序数组,返回这两个数组的中位数。如果中位数有两个,则返回它们的平均值。e.g. [1, 3, 5]和[2, 4, 6]的中位数是3.5解决思路如果两个数组的长度之和为奇数,则中位数有一个;否则中位数为其中两个的平均值。从两个数组中找第k个数,可以使用递归的思路。程序首先,写出在有序... 阅读全文
posted @ 2015-07-12 15:57 Chapter 阅读(348) 评论(0) 推荐(0)
摘要:问题描述主元素的定义为:数组中出现次数超过数组长度一半以上的元素。输入一个无序数组,输出主元素(不能保证一定存在主元素)。解决思路经典的芯片测试问题:1. 首先将数组的首元素置为主元素候选,并附加一个计数器,初始为1;2. 遍历数组之后的元素,如果元素与候选元素相等,计数器加1;否则计数器减1;途中... 阅读全文
posted @ 2015-06-30 11:49 Chapter 阅读(985) 评论(0) 推荐(0)