数组
六种鱼
这个作者很懒,什么都没留下…
展开
-
LintCode 两数之和
给一个整数数组,找到两个数使得他们的和等于一个给定的数 target。你需要实现的函数twoSum需要返回这两个数的下标, 并且第一个下标小于第二个下标。注意这里下标的范围是 1 到 n,不是以 0 开头。Notice你可以假设只有一组答案。Example 给出 numbers = [2, 7, 11, 15], target = 9, 返回 [1, 2]. Either of the foll原创 2017-09-26 11:20:35 · 253 阅读 · 0 评论 -
二维数组斜行遍历
public class test { public static void main(String[] args){ int n =9; int[][] a = new int[n][n]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ a[i]原创 2017-09-18 11:30:26 · 2851 阅读 · 0 评论 -
LintCode 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 is only one duplicate number, fin原创 2017-10-23 14:25:59 · 218 阅读 · 0 评论 -
LintCode 买卖股票的最佳时机 III
假设你有一个数组,它的第i个元素是一支给定的股票在第i天的价格。设计一个算法来找到最大的利润。你最多可以完成两笔交易。注意事项你不可以同时参与多笔交易(你必须在再次购买前出售掉之前的股票)样例 给出一个样例数组 [4,4,6,1,1,4,2,5], 返回 6利用两个数组left 和right,left[i]存第i天及之前的某一天卖掉股票能赚到的最大利润,right[i]存第i天及第i天之后的某一天原创 2017-10-31 15:59:19 · 396 阅读 · 0 评论