LeetCode 刷题学习
qq_26495925
这个作者很懒,什么都没留下…
展开
-
刷题总结#8
#287. Find the Duplicate Number Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there原创 2017-04-06 23:41:37 · 153 阅读 · 0 评论 -
刷题总结#16
#334. Increasing Triplet Subsequence Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should: Return true if there exists原创 2017-04-26 14:23:20 · 181 阅读 · 0 评论 -
刷题总结#4
#421 Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ i, j < n. Input: [3, 10, 5, 25, 2, 8]Output: 28Explanation: The maxi原创 2017-04-04 02:11:56 · 280 阅读 · 0 评论 -
刷题总结#15
#380 Insert Delete GetRandom O(1) 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)原创 2017-04-25 11:23:06 · 187 阅读 · 0 评论 -
刷题总结#13
#390. Elimination Game There is a list of sorted integers from 1 to n. Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.Repeat原创 2017-04-16 20:40:50 · 191 阅读 · 0 评论 -
刷题总结#7
#452. Minimum Number of Arrows to Burst Balloons There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the hor原创 2017-04-05 23:03:02 · 188 阅读 · 0 评论 -
刷题总结#6
#378. Kth Smallest Element in a Sorted Matrix Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the k原创 2017-04-05 11:41:51 · 227 阅读 · 0 评论 -
#刷题总结5
#486. Predict the Winner Given an array of scores that are non-negative integers. Player 1 picks one of the numbers from either end of the array followed by the player 2 and then player 1 and so on.原创 2017-04-04 17:34:36 · 165 阅读 · 0 评论 -
刷题总结#3
# 382 一个listnode列表,等可能地获得一个数,通过遍历实现 假设有n个,每个概率为1/n,但是遍历的时候遍历到k(k < n),第k个概率为1/k,【不选中k后一个的概率为k/n】,所以最后算选到k的概率还是1/n。 int getRandom() { int res = head->val; ListNode* node原创 2017-04-03 18:55:54 · 142 阅读 · 0 评论 -
刷题总结#12
#424. Longest Repeating Character Replacement 好巧妙的一道题! Given a string that consists of only uppercase English letters, you can replace any letter in the string with another letter at most k times.原创 2017-04-12 14:30:28 · 144 阅读 · 0 评论 -
刷题总结#2
1.从一句话中读取每一个单词 eg: i have an apple and i have a pen string s=这句话; string ans; istringstream is(s); while(is>>tmp) { ans=tmp; }原创 2017-04-03 10:25:24 · 192 阅读 · 0 评论 -
刷题总结#11
#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.O(n原创 2017-04-10 23:11:28 · 140 阅读 · 0 评论 -
刷题总结#1
注意添加头文件#include 要用到sort,注意采用#include 对一个pair原创 2017-03-30 21:58:58 · 204 阅读 · 0 评论 -
刷题总结#11
#319. Bulb Switcher There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’原创 2017-04-09 00:00:14 · 235 阅读 · 0 评论 -
刷题总结#10
这道题其实挺简单的,如果把警察的监视范围当作一个pair < int,int>来排序比较的话,时间是超的。 那么我们把监视范围的left,right。在一个nums的数组中表示。 nums[left]+1,nums[right+1]-1; cnt记录此时nums数组的和。 如果有值,表示监视。 #include #include #include #include #in原创 2017-04-07 21:25:57 · 172 阅读 · 0 评论 -
刷题总结#9
#241. Different Ways to Add Parentheses Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid原创 2017-04-07 17:53:09 · 254 阅读 · 0 评论 -
刷题总结#17
#48. Rotate Image You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise)./* * clockwise rotate * first reverse up to down, then swap the symmetry * 1 2原创 2017-05-08 21:52:21 · 191 阅读 · 0 评论