Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
1 | Input: "hello" |
Example 2:
1 | Input: "leetcode" |
Note:
The vowels does not include the letter “y”.
Write a function that takes a string as input and reverse only the vowels of a string.
Example 1:
1 | Input: "hello" |
Example 2:
1 | Input: "leetcode" |
Note:
The vowels does not include the letter “y”.
Write a function that reverses a string. The input string is given as an array of characters char[]
.
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
You may assume all the characters consist of printable ascii characters.
Example 1:
1 | Input: ["h","e","l","l","o"] |
Example 2:
1 | Input: ["H","a","n","n","a","h"] |
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:
1 | Input: "A man, a plan, a canal: Panama" |
Example 2:
1 | Input: "race a car" |
Constraints:
s
consists only of printable ASCII characters.Given a string s consists of upper/lower-case alphabets and empty space characters ' '
, return the length of last word (last word means the last appearing word if we loop from left to right) in the string.
If the last word does not exist, return 0.
Note: A word is defined as a maximal substring consisting of non-space characters only.
Example:
1 | Input: "Hello World" |
Given a string s
, find the length of the longest substring without repeating characters.
Example 1:
1 | Input: s = "abcabcbb" |
Example 2:
1 | Input: s = "bbbbb" |
Example 3:
1 | Input: s = "pwwkew" |
Example 4:
1 | Input: s = "" |
Constraints:
0 <= s.length <= 5 * 104
s
consists of English letters, digits, symbols and spaces.Given two binary strings, return their sum (also a binary string).
The input strings are both non-empty and contains only characters 1
or 0
.
Example 1:
1 | Input: a = "11", b = "1" |
Example 2:
1 | Input: a = "1010", b = "1011" |
Constraints:
'0'
or '1'
characters.1 <= a.length, b.length <= 10^4
"0"
or doesn’t contain any leading zero.Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Example 1:
1 | Input: |
Example 2:
1 | Input: |
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.
Example:
1 | board = |
Constraints:
board
and word
consists only of lowercase and uppercase English letters.1 <= board.length <= 200
1 <= board[i].length <= 200
1 <= word.length <= 10^3
Given two non-negative integers num1
and num2
represented as strings, return the product of num1
and num2
, also represented as a string.
Example 1:
1 | Input: num1 = "2", num2 = "3" |
Example 2:
1 | Input: num1 = "123", num2 = "456" |
Note:
num1
and num2
is < 110.num1
and num2
contain only digits 0-9
.num1
and num2
do not contain any leading zero, except the number 0 itself.The count-and-say sequence is the sequence of integers with the first five terms as following:
1 | 1. 1 |
1
is read off as "one 1"
or 11
.11
is read off as "two 1s"
or 21
.21
is read off as "one 2
, then one 1"
or 1211
.
Given an integer n where 1 ≤ n ≤ 30, generate the nth term of the count-and-say sequence. You can do so recursively, in other words from the previous member read off the digits, counting the number of digits in groups of the same digit.
Note: Each term of the sequence of integers will be represented as a string.