leetcode 583. Delete Operation for Two Strings

leetcode
九章

题目描述

Given two words word1 and word2 , find the minimum number of steps
required to make word1 and word2 the same, where in each step you can
delete one character in either string.

Example 1:

Input: "sea", "eat"
Output: 2
Explanation: You need one step to make "sea" to "ea" and another step to make "eat" to "ea".

Note:

  1. The length of given words won’t exceed 500.
  2. Characters in given words can only be lower-case letters.

Tags: String

Difficulty: Medium

答案



leetcode 10. Regular Expression Matching

leetcode
九章

题目描述

Given an input string (s) and a pattern (p), implement regular expression
matching with support for '.' and '*'.
‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.

The matching should cover the entire input string (not partial).

Note:

  • s could be empty and contains only lowercase letters a-z.
  • p could be empty and contains only lowercase letters a-z, and characters like . or *.

Example 1:
Input: s = “aa” p = “a” Output: false Explanation: “a” does not match the entire string “aa”.

Example 2:
Input: s = “aa” p = “a*” Output: true Explanation: ‘*’ means zero or more of the preceding element, ‘a’. Therefore, by repeating ‘a’ once, it becomes “aa”.

Example 3:
Input: s = “ab” p = “.*” Output: true Explanation: “.*” means “zero or more (*) of any character (.)”.

Example 4:
Input: s = “aab” p = “cab” Output: true Explanation: c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches “aab”.

Example 5:
Input: s = “mississippi” p = “misis*p.” Output: false

Tags: String, Dynamic Programming, Backtracking

Difficulty: Hard

答案



leetcode 44. Wildcard Matching

leetcode
九章

题目描述

Given an input string (s) and a pattern (p), implement wildcard pattern
matching with support for '?' and '*'.

'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).

The matching should cover the entire input string (not partial).

Note:

  • s could be empty and contains only lowercase letters a-z.
  • p could be empty and contains only lowercase letters a-z, and characters like ? or *.

Example 1:

Input:
s = "aa"
p = "a"
Output: false
Explanation: "a" does not match the entire string "aa".

Example 2:

Input:
s = "aa"
p = "*"
Output: true
Explanation:  '*' matches any sequence.

Example 3:

Input:
s = "cb"
p = "?a"
Output: false
Explanation:  '?' matches 'c', but the second letter is 'a', which does not match 'b'.

Example 4:

Input:
s = "adceb"
p = "*a*b"
Output: true
Explanation:  The first '*' matches the empty sequence, while the second '*' matches the substring "dce".

Example 5:

Input:
s = "acdcb"
p = "a*c?b"
Output: false

Tags: String, Dynamic Programming, Backtracking, Greedy

Difficulty: Hard

答案



leetcode 32. Longest Valid Parentheses

leetcode
九章

题目描述

Given a string containing just the characters '(' and ')', find the length
of the longest valid (well-formed) parentheses substring.

Example 1:

Input: "(()"
Output: 2
Explanation: The longest valid parentheses substring is "()"

Example 2:

Input: ")()())"
Output: 4
Explanation: The longest valid parentheses substring is "()()"

Tags: String, Dynamic Programming

Difficulty: Hard

答案



leetcode 125. Valid Palindrome

leetcode
九章

题目描述

Given a string, determine if it is a palindrome, considering only alphanumeric
characters and ignoring cases.

Note: For the purpose of this problem, we define empty string as valid
palindrome.

Example 1:

Input: "A man, a plan, a canal: Panama"
Output: true

Example 2:

Input: "race a car"
Output: false

Tags: Two Pointers, String

Difficulty: Easy

答案



leetcode 680. Valid Palindrome II

leetcode
九章

题目描述

Given a non-empty string s, you may delete at most one character. Judge
whether you can make it a palindrome.

Example 1:

Input: "aba"
Output: True

Example 2:

Input: "abca"
Output: True
Explanation: You could delete the character 'c'.

Note:

  1. The string will only contain lowercase characters a-z. The maximum length of the string is 50000.

Tags: String

Difficulty: Easy

答案



leetcode 387. First Unique Character in a String

leetcode
九章

题目描述

Given a string, find the first non-repeating character in it and return it’s
index. If it doesn’t exist, return -1.

Examples:

s = "leetcode"
return 0.

s = "loveleetcode",
return 2.

Note: You may assume the string contain only lowercase letters.

Tags: Hash Table, String

Difficulty: Easy

答案



leetcode 72. Edit Distance

leetcode
九章

题目描述

Given two words word1 and word2 , find the minimum number of operations
required to convert word1 to word2.

You have the following 3 operations permitted on a word:

  1. Insert a character
  2. Delete a character
  3. Replace a character

Example 1:

Input: word1 = "horse", word2 = "ros"
Output: 3
Explanation: 
horse -> rorse (replace 'h' with 'r')
rorse -> rose (remove 'r')
rose -> ros (remove 'e')

Example 2:

Input: word1 = "intention", word2 = "execution"
Output: 5
Explanation: 
intention -> inention (remove 't')
inention -> enention (replace 'i' with 'e')
enention -> exention (replace 'n' with 'x')
exention -> exection (replace 'n' with 'c')
exection -> execution (insert 'u')

Tags: String, Dynamic Programming

Difficulty: Hard

答案



leetcode 678. Valid Parenthesis String

leetcode
九章

题目描述

Given a string containing only three types of characters: ‘(‘, ‘)’ and ‘*’,
write a function to check whether this string is valid. We define the validity
of a string by these rules:

  1. Any left parenthesis '(' must have a corresponding right parenthesis ')'.
  2. Any right parenthesis ')' must have a corresponding left parenthesis '('.
  3. Left parenthesis '(' must go before the corresponding right parenthesis ')'.
  4. '*' could be treated as a single right parenthesis ')' or a single left parenthesis '(' or an empty string.
  5. An empty string is also valid.

Example 1:

Input: "()"
Output: True

Example 2:

Input: "(*)"
Output: True

Example 3:

Input: "(*))"
Output: True

Note:

  1. The string size will be in the range [1, 100].

Tags: String

Difficulty: Medium

答案



leetcode 3. Longest Substring Without Repeating Characters

难度:Middle

leetcode
九章

题目描述

Given a string, find the length of the longest substring without repeating
characters.

Example 1:

Input: "abcabcbb"
Output: 3 
Explanation: The answer is "abc", with the length of 3. 

Example 2:

Input: "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.

Example 3:

Input: "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3. 
             Note that the answer must be a **substring** , "pwke" is a _subsequence_ and not a substring.

Tags: Hash Table, Two Pointers, String, Sliding Window

Difficulty: Medium

答案


:D 一言句子获取中...