
Array
pengweixuan008
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
217.Contains Duplicate(判断一个数组是否有重复数出现)
题目:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every eleme原创 2015-07-28 15:57:55 · 354 阅读 · 0 评论 -
198.House Robber (求非相邻正整数的和最大值)
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2015-07-29 11:14:09 · 306 阅读 · 0 评论 -
169.Majority Element (数组中出现次数超过一半的数)
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.思路:方法一:将数组排序,最中间的那个数就是您要找的数。方法二:用了两个辅助变量。 k用于临时存储数组中的数原创 2015-07-29 14:06:59 · 281 阅读 · 0 评论 -
162.Find Peak Element (寻找数组中的峰值点)
题目:A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple p原创 2015-07-30 14:14:27 · 574 阅读 · 0 评论 -
136.Single Number (数组中只出现一次的数)
Given an array of integers, every element appears twice except for one. Find that single one.代码:public class Solution { public int singleNumber(int[] nums) { HashMap map = new Hash原创 2015-07-30 15:11:01 · 230 阅读 · 0 评论 -
1.Two Sum (数组中两个数之和为n)
Given an array of integers, find two numbers such that they add up to a specific target number.Input: numbers={2, 7, 11, 15}, target=9Output: index1=1, index2=2代码:public class Solution原创 2015-08-03 14:27:57 · 460 阅读 · 0 评论