- 博客(4)
- 收藏
- 关注
原创 LeetCode219:存在重复 II
迭代,这个题目写的怪怪的class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { for(int i=0;i<nums.length-1;i++) { for(int j=i+1;j<nums.length;j++) if(nums[i]==nums[j...
2018-04-21 17:11:28 269
原创 LeetCode122:买卖股票的最佳时机 II(动态规划)
动态规划:1.class Solution { public int maxProfit(int[] prices) { int[] profit = new int[prices.length]; if(prices.length==0) return 0; for (int i = 0; i < prices.length; i++) ...
2018-04-21 16:38:57 1143
原创 LeetCode121:买卖股票的最佳时机
class Solution { public int maxProfit(int[] prices) { int max=0; int count=0; if(prices.length<=1) return 0; for(int i=0;i<prices.length-1;...
2018-04-20 16:38:07 296
原创 最大子序和
之前在博客搜到的算法复杂度为O(N)的最大子序和并没有考虑到都为负数的情况,因此改进为如下算法public class MaxSubArray53 { public static void main(String[] args) { int[] nums = { 4, 1, -3, 4, 1, 2, 1, 1, 4 }; int sum=0; int maxSum=-21474836...
2018-04-20 16:23:25 223
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人