This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} s | |
* @param {number} k | |
* @return {string} | |
*/ | |
var reverseStr = function(s, k) { | |
let reverseFrom = (i, j) => { | |
s = s.split(""); | |
while(i<j) { | |
let temp = s[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string[]} strs | |
* @return {string[][]} | |
*/ | |
var groupAnagrams = function(strs) { | |
let map = {}; | |
let res = []; | |
for(let i=0; i<strs.length; i++) { | |
let temp = strs[i].split(""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} s | |
* @return {string} | |
*/ | |
var longestPalindrome = function(s) { | |
let res = ""; | |
let max = 0; | |
for(let i=0; i<s.length; i++) { | |
let l = i; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number} x | |
* @param {number} y | |
* @return {number} | |
*/ | |
var hammingDistance = function(x, y) { | |
let xor = x ^ y; | |
let count = 0; | |
while (xor != 0) { | |
xor &= xor - 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} s | |
* @param {string} t | |
* @return {boolean} | |
*/ | |
var isAnagram = function(s, t) { | |
if(s.length != t.length) return false; | |
let dict = {}; | |
for(let i=0; i<s.length; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {character[]} s | |
* @return {void} Do not return anything, modify s in-place instead. | |
*/ | |
var reverseString = function(s) { | |
let start = 0; | |
let end = s.length - 1; | |
let temp = ""; | |
while(start <= end) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {string} s | |
* @return {boolean} | |
*/ | |
var isPalindrome = function(s) { | |
const regex = /[^a-z0-9]/gmi; | |
s = s.replace(regex, "").toLowerCase(); | |
let l = 0; | |
let r = s.length - 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} nums | |
* @return {number[]} | |
*/ | |
var findDisappearedNumbers = function(nums) { | |
let ans = []; | |
for(let i=0; i<nums.length; i++) { | |
if(nums[Math.abs(nums[i]) - 1] < 0) continue; | |
nums[Math.abs(nums[i]) - 1] = -nums[Math.abs(nums[i]) - 1]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} nums | |
* @return {number} | |
*/ | |
var missingNumber = function(nums) { | |
let sum = ((nums.length) * (nums.length + 1)) / 2; | |
let sum2 = 0; | |
for(let i=0; i<nums.length; i++) { | |
sum2 += nums[i]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {number[]} candidates | |
* @param {number} target | |
* @return {number[][]} | |
*/ | |
var combinationSum = function(candidates, target) { | |
let answer = []; | |
let stack = []; | |
let findCombinations = (index, targetToFind, stack, answer, candidates) => { | |
if(index === candidates.length) { |