LeetCode
小何不吃姜
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
LeetCode(5)Longest Palindromic Substring最长回文子串
输出S中的最长回文串eg.Input: s = "babad"Output: "bab"Approach 1纯暴力匹配,提交超时Approcah 2 Manacher算法将暴力匹配的算法复杂度提升到O(n),先对S进行处理,每个字符前后插入"#"(或其他S内不可能出现的字符),经过处理的S'长度一定为奇数,分别以每一个字符为中心计算他的回文半径len,原字符串中它的回文长度为len-1,所以问题变为求每一个字符的len[i]。p:最右回文边界center:当前p的中心.原创 2021-07-16 11:10:11 · 135 阅读 · 0 评论 -
Dynamic Programming动态规划
1、介绍 动态规划是通过组合子问题的解而解决整个问题,动态规划适用于子问题不是独立的情况,也就是各子问题包含公共的子子问题。动态规划算法对每个子子问题只求解一次,将其结果保存在一张表中,从而避免每次遇到各个子问题时重新计算。 动态规划通常应用于最优化问题,此类问题可能有很多种可行解。每个解有一个值,而我们希望找出一个具有最优(最大或最小)值的解。称这样的解为该问题的“一个”最优解(而不是“确定”的“最优解”),因为可能存在多个取最优值的解。 动态规划算法...原创 2021-06-29 14:10:25 · 128 阅读 · 0 评论 -
LeetCode(66)Plus One
题目:Given anon-emptyarray of decimal digitsrepresenting a non-negative integer, incrementone to the integer.The digits are stored such that the most significant digit is at the head of the list, and each element in the array contains a single digit....原创 2021-06-10 14:37:42 · 119 阅读 · 0 评论 -
LeetCode(53)Maximum Subarray
题目:Given an integer arraynums, find the contiguous subarray (containing at least one number) which has the largest sum and returnits sum.思路:返回由相邻数组相加得到的最大的和class Solution { public int maxSubArray(int[] nums) { int sum = nums[0]; in..原创 2021-06-07 17:37:33 · 145 阅读 · 0 评论 -
LeetCode(21) Merge Two Sorted Lists
题目:Merge two sorted linked lists and return it as asortedlist. The list should be made by splicing together the nodes of the first two lists.将两个ListNode按照顺序拼接成一个,一开始想通过l1.val和l2.val比较大小,再借助ListNode temp将其插入至其中一个ListNode中,但在一开始调试过程中发现,若temp=q;(q=l2...原创 2021-06-02 09:46:39 · 131 阅读 · 0 评论 -
LeetCode(14)Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string"".思路:要求输出strs中最长重复的字符串,使用String类中的compareTo()方法比较字符串,使用substring(int beginIndex,int endIndex)截取字符串。该方法判断较.原创 2021-05-25 13:37:00 · 112 阅读 · 0 评论 -
LeetCode 2.Add Two Numbers
题目:You are given twonon-emptylinked lists representing two non-negative integers. The digits are stored inreverse order, and each of their nodes contains a single digit. Add the two numbers and return the sumas a linked list.You may assume the two ...原创 2021-05-18 14:29:22 · 133 阅读 · 0 评论 -
LeetCode刷题(一)Two Sum
题目:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the ...原创 2019-05-14 09:56:30 · 184 阅读 · 0 评论
分享