摘要: Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the  阅读全文
posted @ 2017-10-14 21:47 daniel456 阅读(154) 评论(0) 推荐(0) 编辑
摘要: 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 arr 阅读全文
posted @ 2017-10-14 21:36 daniel456 阅读(106) 评论(0) 推荐(0) 编辑
摘要: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Not 阅读全文
posted @ 2017-10-14 21:34 daniel456 阅读(94) 评论(0) 推荐(0) 编辑
摘要: Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times. You may assume that the 阅读全文
posted @ 2017-10-14 21:24 daniel456 阅读(103) 评论(0) 推荐(0) 编辑
摘要: Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function 阅读全文
posted @ 2017-10-14 21:22 daniel456 阅读(126) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple 阅读全文
posted @ 2017-10-14 21:16 daniel456 阅读(128) 评论(0) 推荐(0) 编辑
摘要: Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction 阅读全文
posted @ 2017-10-14 21:13 daniel456 阅读(133) 评论(0) 推荐(0) 编辑
摘要: [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 含义:要求计算杨辉三角第K行的元素,For example, given k = 3,Return [1,3,3,1]. 思路: 同https://www.cnblogs.com/wzj4858/p/76 阅读全文
posted @ 2017-10-14 21:05 daniel456 阅读(96) 评论(0) 推荐(0) 编辑
摘要: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 阅读全文
posted @ 2017-10-14 20:28 daniel456 阅读(100) 评论(0) 推荐(0) 编辑
摘要: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. Note:You may assume that nums1 has enough space (size tha 阅读全文
posted @ 2017-10-14 20:26 daniel456 阅读(82) 评论(0) 推荐(0) 编辑
摘要: Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leadin 阅读全文
posted @ 2017-10-14 20:20 daniel456 阅读(157) 评论(0) 推荐(0) 编辑
摘要: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2, 阅读全文
posted @ 2017-10-14 20:12 daniel456 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or 阅读全文
posted @ 2017-10-14 20:09 daniel456 阅读(88) 评论(0) 推荐(0) 编辑
摘要: Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you 阅读全文
posted @ 2017-10-14 20:05 daniel456 阅读(93) 评论(0) 推荐(0) 编辑
摘要: 给定一个有序数组,原地删除重复元素,使得每个元素只出现一次,并返回新的长度。不为另一个数组分配额外空间,必须用常量内存做到这一点。 阅读全文
posted @ 2017-10-14 20:02 daniel456 阅读(99) 评论(0) 推荐(0) 编辑
摘要: 题目:给定一个整型数组,返回两个数的下标,满足两个数相加为一个特定整数。假定只有一个正确答案 例如: nums = [2, 7, 11, 15], target = 9,因为nums[0] + nums[1] = 2 + 7 = 9,返回[0,1] 思路:如果是只返回两个数,可以将数组排序后,从两边 阅读全文
posted @ 2017-10-14 19:44 daniel456 阅读(129) 评论(0) 推荐(0) 编辑