![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 76
cndn_gfz
这个作者很懒,什么都没留下…
展开
-
[leetcode]289. Game of Life (java)
题目:According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970."Given a board原创 2016-12-12 19:30:56 · 891 阅读 · 0 评论 -
[leetcode]74. Search a 2D Matrix
题目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 sorted from left to right.The first integer原创 2017-03-15 15:12:40 · 428 阅读 · 0 评论 -
[leetcode]202.Happy Number
题目Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the原创 2017-03-06 16:10:08 · 330 阅读 · 0 评论 -
[leetcode]264. Ugly Number II
题目Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of th原创 2017-03-08 14:19:00 · 249 阅读 · 0 评论 -
【leetcode】150. Evaluate Reverse Polish Notation
题目Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.Some examples: ["2原创 2017-03-02 16:37:53 · 250 阅读 · 0 评论 -
LeetCode—381. Insert Delete GetRandom O(1) - Duplicates allowed (java)
问题:Note: Duplicate elements are allowed.insert(val): Inserts an item val to the collection.remove(val): Removes an item val from the collection if present.getRandom: Returns a random element原创 2016-12-07 19:23:03 · 331 阅读 · 0 评论 -
[leetcode] 370. Range Addition
问题Assume you have an array of length n initialized with all 0's and are given k update operations.Each operation is represented as a triplet: [startIndex, endIndex, inc] which increments e原创 2016-12-13 12:17:39 · 309 阅读 · 0 评论 -
蓄水池抽样算法
问题定义长度为N的链表,N很大,但是不知道具体有多大。从N个元素中随机取出K个元素,只能遍历一次链表。用到的算法保证取出的元素恰好有K个,且他们是完全随机的(出现概率均相等)。求解该算法是针对从一个序列中随机抽取不重复的K个数,保证每个数被抽取到的概率为k/n这个问题而构建的。做法是:首先构建一个可放K个元素的蓄水池,将序列的前K个元素放入蓄水池中。然后从第K+1个元素开始原创 2016-12-01 09:33:00 · 428 阅读 · 0 评论 -
[Leetcode]398. Random Pick Index
题目:Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.Note:The原创 2016-11-30 17:11:31 · 258 阅读 · 0 评论 -
LeetCode:382 Linked List Random Node蓄水池抽样算法
问题定义长度为N的链表,N很大,但是不知道具体有多大。从N个元素中随机取出K个元素,只能遍历一次链表。用到的算法保证取出的元素恰好有K个,且他们是完全随机的(出现概率均相等)。求解该算法是针对从一个序列中随机抽取不重复的K个数,保证每个数被抽取到的概率为k/n这个问题而构建的。做法是:首先构建一个可放K个元素的蓄水池,将序列的前K个元素放入蓄水池中。然后从第K+1个元素开始原创 2016-12-01 10:32:01 · 765 阅读 · 0 评论 -
Silding Window Maximum(滑动窗口的最大值)
一,问题描述 给定一个整数数组nums 和一个正整数k的滑动窗口,滑动窗口每次从左到右移动一个数字,返回每次滑动窗口中的最大值。2,例如: 输入: nums=[1,2,3,4,5,6,7], k=3 输出: 3,4,5,6,73,解题思路: 首先判断数组的长度len与k的大小,如果lenk的话,则定义一个数组data,其长度为len-k+1。然后对于原创 2016-12-01 17:01:32 · 449 阅读 · 0 评论 -
LeetCode 448.Find All Number Disappeared in an Array
问题Given an array of integers where 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements of [1, n] inclusive that do not appear in this ar原创 2016-12-05 09:37:39 · 817 阅读 · 0 评论 -
[leetcode]442. Find All Duplicates in an Array(java)
问题:Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array), some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it wit原创 2016-12-05 19:32:25 · 1340 阅读 · 0 评论 -
[Leetcode]414. Third Maximum Number
问题:Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n).Example 1:Inpu原创 2016-12-06 11:23:59 · 211 阅读 · 0 评论 -
[leetcode]240. Search a 2D Matrix II
题目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 sorted in ascending from left to right.Inte原创 2017-03-16 10:06:39 · 426 阅读 · 0 评论