天天看点

Leetcode练题系列(六): 字符串相关的算法

LeetCode

  ​​英文官网(推荐)​​

  ​​中文官网​​

  从2016年大二左右开始就接触算法,起初也简单练习过,但现在工作一段时间后,随着代码水平的提高(​

​自我感觉​

​),算法水平一直没有进步哈,所以记录下来相关题目,不断练习。

提前说说刷题的心得:

  • 只有算法不薄弱才能拿高工资,如果你想当一个nb的程序员,现在开始努力吧 !
  • 坚持,积少成多。万事开头难

  在题目预览表中,会有题目的编号和题目的难易程度,但是我认为,题目的难易程度并不能真的确定它难还是不难,只是人为对他评价而已,有些难的题确实 Easy。

  因为面试中遇到几次都是LeetCode原题,并且是英文题目,题目的​

​标题​

​​都是LeetCode​

​英文官网​

​​的链接地址。​

​题目的编号​

​​是​

​中文​

​官网地址。

题目预览表

​​String​​

  按心情排序,在地铁上看到哪个题目就收藏下来的,然后有时间就做 ! !

# Title Difficulty
​​718​​ ​​Maximum Length of Repeated Subarray​​ Medium
​​583​​ ​​Delete Operation for Two Strings​​ Medium
​​678​​ ​​Valid Parenthesis String​​ Medium
​​680​​ ​​Valid Palindrome II​​ Easy
​​686​​ ​​Repeated String Match​​ Easy
​​20​​ ​​ Valid Parentheses​​ Easy
​​32​​ ​​ Longest Valid Parentheses ​​ Hard
​​3​​ ​​ Longest Substring Without Repeating Characters​​ Medium
​​300​​ ​​ Longest Increasing Subsequence​​ Medium
​​673​​ ​​ Number of Longest Increasing Subsequence​​ Medium

718. [Maximum Length of Repeated Subarray

Leetcode练题系列(六): 字符串相关的算法

状态转移方程:​

​dp[i][j]=dp[i-1][j-1]+1​

583. Delete Operation for Two Strings

Leetcode练题系列(六): 字符串相关的算法

状态转移方程:​

​dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1])​

​​ ​

​dp[i][j]=dp[i-1][j-1]+1​

678. Valid Parenthesis String

Leetcode练题系列(六): 字符串相关的算法

1.利用两个栈分别存储左括号和星星的坐标,防止出现替换后出现​

​**((*​

​ 对坐标进行比较

2.start as left or right, if as left, too low while be ignore to 0 ,right must greater than 0

680. Valid Palindrome II

Leetcode练题系列(六): 字符串相关的算法

注意 s.substring(start, end) start保留 end不保留

Leetcode练题系列(六): 字符串相关的算法

686. Repeated String Match

Leetcode练题系列(六): 字符串相关的算法

do repeat

20. Valid Parentheses

Leetcode练题系列(六): 字符串相关的算法

use stack

32. Longest Valid Parentheses

Leetcode练题系列(六): 字符串相关的算法

stack push interval position

3. Longest Substring Without Repeating Characters

Leetcode练题系列(六): 字符串相关的算法

care for interval and conversion

300. Longest Increasing Subsequence

Leetcode练题系列(六): 字符串相关的算法

binary search

673. Number of Longest Increasing Subsequence

Leetcode练题系列(六): 字符串相关的算法

一些总结

  1. StringBuilder 中的 ​

    ​setLength(0)​

    ​ 可以将Sb从头开始