Dynamic Programming 面试题与答案
问题 11. Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) that has the largest product.
Example:
Input: [2, 3, -2, 4], Output: 6 (subarray [2, 3])
问题 12. Decode Ways
A message containing letters from A-Z can be encoded into numbers. Given a non-empty string containing only digits, determine the total number of ways to decode it.
Example:
Input: "226", Output: 3 ("22" can be decoded as "BB", "2" + "2" + "6" can be decoded as "VVF")
问题 13. Word Break Problem
Given a non-empty string and a dictionary of words, determine if the string can be segmented into a space-separated sequence of one or more dictionary words.
Example:
Input: s = "leetcode", wordDict = ["leet", "code"], Output: true
问题 14. Count Palindromic Subsequences
Given a string, find the number of distinct palindromic subsequences of it.
Example:
Input: "bccb", Output: 6 ("b", "c", "c", "b", "ccb", "bccb")
问题 15. Minimum Path Sum
Given a grid filled with non-negative numbers, find a path from the top-left to the bottom-right corner that minimizes the sum of numbers along the path.
Example:
Grid: [[1,3,1],[1,5,1],[4,2,1]], Output: 7 (1 -> 3 -> 1 -> 1 -> 1)
用户评价最有帮助的内容: