Given two strings s
and t
, return true
if they are equal when both are typed into empty text editors. '#'
means a backspace character.
Note that after backspacing an empty text, the text will continue empty.
Example 1:
Example 2:
Example 3:
1 <= s.length, t.length <= 200
s
and t
only contain lowercase letters and '#'
characters./**
* @param {string} s
* @param {string} t
* @return {boolean}
*/
var backspaceCompare = function(s, t) {
return excuteBackspace(s) === excuteBackspace(t);
};
var excuteBackspace = function(str) {
const stack = [];
for (let i = 0; i < str.length; i++) {
if (str[i] === '#') {
stack.pop();
} else {
stack.push(str[i]);
}
}
return stack.join('');
}
Given a string s
, you can transform every letter individually to be lowercase or uppercase to create another string.
Return a list of all possible strings we could create. Return the output in any order.
Example 1:
Example 2:
1 <= s.length <= 12
s
consists of lowercase English letters, uppercase English letters, and digits./**
* @param {string} s
* @return {string[]}
*/
var letterCasePermutation = function(s) {
const alphabetRegExp = /[a-zA-Z]/;
const result = [];
const getPermutation = function (index, arr) {
if (arr.length === s.length) {
result.push(arr.join(''));
return;
}
const letter = s[index];
if (alphabetRegExp.test(letter)) {
getPermutation(index + 1, [...arr, letter.toLowerCase()]);
getPermutation(index + 1, [...arr, letter.toUpperCase()]);
} else {
getPermutation(index + 1, [...arr, letter]);
}
}
getPermutation(0, []);
return result;
}
s
, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.1 <= s.length <= 5 * 10^4
s
contains printable ASCII characters.s
does not contain any leading or trailing spaces.s
are separated by a single space./**
* @param {string} s
* @return {string}
*/
var reverseWords = function(s) {
return s.split(' ').map((str) => {
let reversedStr = '';
for (let i = str.length - 1; i >=0; i--) {
reversedStr = reversedStr + str[i];
}
return reversedStr;
}).join(' ');
};