Valid Palindrome II
Given a non-empty string
s, you may delete at most one character. Judge whether you can make it a palindrome.
Input: "aba" Output: True
Input: "abca" Output: True Explanation: You could delete the character 'c'.
- The string will only contain lowercase characters a-z. The maximum length of the string is 50000.
Map Sum Pairs
Implement a MapSum class with
For the method
insert, you’ll be given a pair of (string, integer). The string represents the key and the integer represents the value. If the key already existed, then the original key-value pair will be overridden to the new one.
For the method
sum, you’ll be given a string representing the prefix, and you need to return the sum of all the pairs’ value whose key starts with the prefix.
Input: insert("apple", 3), Output: Null Input: sum("ap"), Output: 3 Input: insert("app", 2), Output: Null Input: sum("ap"), Output: 5
Valid Parenthesis String
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:
- Any left parenthesis
'('must have a corresponding right parenthesis
- Any right parenthesis
')'must have a corresponding left parenthesis
- Left parenthesis
'('must go before the corresponding right parenthesis
'*'could be treated as a single right parenthesis
')'or a single left parenthesis
'('or an empty string.
- An empty string is also valid.
Input: "()" Output: True
Input: "(*)" Output: True
Input: "(*))" Output: True
- The string size will be in the range [1, 100].
You have 4 cards each containing a number from 1 to 9. You need to judge whether they could operated through
) to get the value of 24.
Input: [4, 1, 8, 7] Output: True Explanation: (8-4) * (7-1) = 24
Input: [1, 2, 1, 2] Output: False
- The division operator
/represents real division, not integer division. For example, 4 / (1 - 2/3) = 12.
- Every operation done is between two numbers. In particular, we cannot use
-as a unary operator. For example, with
[1, 1, 1, 1]as input, the expression
-1 - 1 - 1 - 1is not allowed.
- You cannot concatenate numbers together. For example, if the input is
[1, 2, 1, 2], we cannot write this as 12 + 12.