zoukankan      html  css  js  c++  java
  • leetcode 300 最长递增子序列

    简介

    dp 经典问题

    code

    class Solution {
    public:
        int lengthOfLIS(vector<int>& nums) {
            int maxLength = 0;
            vector<int> nums1(nums.size(), 1);
            for(int j=0; j<nums.size(); j++){
                for(int i = 0; i<j; i++){
                    if(nums[i] < nums[j]) nums1[j] = max(nums1[i] + 1, nums1[j]);
                }
            }
            for(auto it:nums1){
                if(it > maxLength){
                    maxLength = it;
                }
            }
            return maxLength;
        }
    };
    
    class Solution {
        public int lengthOfLIS(int[] nums) {
            int n = nums.length;
            ArrayList<Integer> v = new ArrayList<Integer>();
            for(int i=0; i<n; i++){
                v.add(1);
            }
            for(int i=0; i<n; i++){
                for(int j=0; j<i; j++){
                    if(nums[j] < nums[i]){
                        v.set(i, Math.max(v.get(i), v.get(j)+1)); // arrayList set 方法
                    }
                }
            }
            int maxLength = 0;
            for(int it : v){
                if(it > maxLength){
                    maxLength = it;
                }
            }
            return maxLength;
        }
    }
    

    TIPS

    发现 java 的方法确实不如c++方面比如, 没有operator来简化操作.

    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    标准差,绝对中位差
    批处理计时
    四元数压缩
    float类型的存储方式
    通俗易懂理解——浮点与定点的计算机表示及互转
    max MultiRes修改器
    Topogun拓补工具
    3dmax高模到低模烘法线
    在线曲线绘制
    景深
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/14800497.html
Copyright © 2011-2022 走看看