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
/** | |
* Definition for singly-linked list. | |
* function ListNode(val, next) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.next = (next===undefined ? null : next) | |
* } | |
*/ | |
/** | |
* @param {ListNode} head | |
* @return {ListNode} |
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} n | |
* @return {number} | |
*/ | |
var climbStairs = function(n) { | |
if (n === 1) { | |
return 1; | |
} | |
let first = 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 {character[]} s | |
* @return {void} Do not return anything, modify s in-place instead. | |
*/ | |
var reverseString = function(s) { | |
const inputLength = s.length - 1; | |
const end = Math.floor(inputLength / 2); | |
for (let i = 0; i <= end; i++) { | |
[s[i], s[inputLength - i]] = [s[inputLength - i], 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
/** | |
* Definition for a binary tree node. | |
* function TreeNode(val, left, right) { | |
* this.val = (val===undefined ? 0 : val) | |
* this.left = (left===undefined ? null : left) | |
* this.right = (right===undefined ? null : right) | |
* } | |
*/ | |
/** | |
* @param {TreeNode} root |
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
var kWeakestRows = function(mat, k) { | |
const soldierList = []; | |
for(let i = 0; i < mat.length; i++) { | |
let soldiers = 0; | |
for (j = 0; j < mat[i].length; j++) { | |
if (mat[i][j]) { | |
soldiers++; | |
} | |
} |
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} startValue | |
* @param {number} target | |
* @return {number} | |
*/ | |
var brokenCalc = function(startValue, target) { | |
let steps = 0; | |
while (startValue < target) { | |
steps++; |
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
function fib(value: number): number { | |
let first = 0; | |
let second = 1; | |
if (value <= 2) { | |
return value === 1 ? first : second; | |
} | |
let retValue = 0; | |
for (let i = 3; i <= value; 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} a | |
* @param {string} b | |
* @return {string} | |
*/ | |
var addBinary = function(a, b) { | |
console.log(BigInt("0b"+a, 2) + BigInt("0b"+b, 2)); | |
// align strings |
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[]} digits | |
* @return {number[]} | |
*/ | |
var plusOne = function(digits) { | |
let index = digits.length - 1; | |
while (index >= 0) { | |
if (digits[index] + 1 <= 9) { | |
digits[index] = digits[index] + 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 | |
* @return {number} | |
*/ | |
var lengthOfLastWord = function(s) { | |
let maxWordLength = 0; | |
let startCollecting = false; | |
for (let i = s.length - 1; i >= 0; i--) { | |
if (s[i] === ' ' && startCollecting) { |