Golang | Leetcode Golang题解之第300题最长递增子序列

题目:

题解:

Go 复制代码
func lengthOfLIS(nums []int) int {
    if len(nums)<=1{
        return len(nums)
    }
    dp := make([]int,len(nums))
    for i:=0;i<len(nums);i++{dp[i]=1}

    res := 1
    for i:=1;i<len(nums);i++{
        for j:=0;j<i;j++{
            if nums[i] > nums[j]{
                dp[i] = max(dp[i],dp[j]+1)
                res = max(res,dp[i])
            }
        }
    }

    return res
}


func max(i,j int)int{
    if i>j{
        return i
    }else{
        return j
    }
}
相关推荐
poemyang9 小时前
Goroutine间的“灵魂管道”:Channel如何实现数据同步与因果传递?
golang·并发编程
Lazy龙10 小时前
Golang协程
golang
2351610 小时前
【LeetCode】146. LRU 缓存
java·后端·算法·leetcode·链表·缓存·职场和发展
tkevinjd14 小时前
反转链表及其应用(力扣2130)
数据结构·leetcode·链表
程序员烧烤15 小时前
【leetcode刷题007】leetcode116、117
算法·leetcode
Swift社区18 小时前
LeetCode 395 - 至少有 K 个重复字符的最长子串
算法·leetcode·职场和发展
Espresso Macchiato18 小时前
Leetcode 3710. Maximum Partition Factor
leetcode·职场和发展·广度优先遍历·二分法·leetcode hard·leetcode 3710·leetcode双周赛167
巴里巴气19 小时前
第15题 三数之和
数据结构·算法·leetcode
一根甜苦瓜19 小时前
Go语言Slice的一道骚题
开发语言·后端·golang
驰羽19 小时前
[GO]Go语言泛型详解
开发语言·golang·xcode