This file contains hidden or 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 findAndReplacePattern = function(words, pattern) { | |
| const result = [] | |
| for (let i=0; i < words.length; i++) { | |
| const word = words[i] | |
| if (matchPattern(word, pattern)){ | |
| result.push(word) | |
| } | |
| } | |
| return result | |
| }; |
This file contains hidden or 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
| // Pseudocódigo | |
| plusOne(digits): | |
| done = false | |
| for i=digits.length-1; i >= 0 && !done; i-- | |
| if digits[i] < 9 | |
| digits[i]++ | |
| done = true | |
| else | |
| digits[i] = 0 | |
This file contains hidden or 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 earliestFullBloom = function(plantTime, growTime) { | |
| console.log(plantTime, growTime) | |
| if (plantTime.every(e => e === 0) && growTime.every(e => e === 0)) { | |
| return 1 | |
| } | |
| if (plantTime.every(e => e === 0)) { | |
| const max = Math.max(...growTime) | |
| console.log("max: " + max) | |
| return max |
This file contains hidden or 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 platesBetweenCandles = function(s, queries) { | |
| const result = [] | |
| for (let i=0; i < queries.length; i++) { | |
| const query = queries[i] | |
| result.push(calculate(s, query[0], query[1])) | |
| } | |
| return result | |
| }; | |
| function calculate(s, start, end) { |
This file contains hidden or 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 removeKdigits = function(num, k) { | |
| if (k == num.length) { | |
| return "0" | |
| } | |
| if (k == 0 || num.length == 1) { | |
| return num | |
| } | |
| const substr = num.substring(0, num.length - k + 1) | |
| const minPos = calculateMinPos(substr) |
This file contains hidden or 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 avoidFlood = function(rains) { | |
| const result = [] | |
| const filled = new Set() | |
| return findSolution(rains, filled, result, 0) | |
| }; | |
| function findSolution(rains, filled, result, day) { | |
| if (day >= rains.length) { // lo logramos! | |
| return result | |
| } |
This file contains hidden or 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[]} deliciousness | |
| * @return {number} | |
| */ | |
| var countPairs = function(deliciousness) { | |
| let max = deliciousness[0] | |
| for (let i=1; i < deliciousness.length; i++) { | |
| if (deliciousness[i] > max) { | |
| max = deliciousness[i] | |
| } |
This file contains hidden or 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 minPartitions = function(n) { | |
| const decibinary = calculateDecibinary(n) | |
| const res = parseInt(n, 10) - parseInt(decibinary, 10) | |
| console.log(n, decibinary, res) | |
| if (res === 0) return 1 | |
| return 1 + minPartitions(res.toString()) | |
| }; | |
| function calculateDecibinary(n) { |
This file contains hidden or 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 merge = function(nums1, m, nums2, n) { | |
| let i=0, j=0 | |
| while (j < nums2.length) { // hasta que recurramos nums2 | |
| if (i > m + j) { // terminamos de recorrer nums1 | |
| nums1[m+j] = nums2[j] | |
| i++ | |
| j++ | |
| } else if (nums1[i] <= nums2[j]) { | |
| i++ | |
| } else { // tenemos que correr los elementos e insertar |
This file contains hidden or 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 minFlips = function(target) { | |
| let count = 0 | |
| for (i=0; i < target.length; i++) { | |
| if (parseInt(target[i]) !== count % 2) count++ | |
| } | |
| return count | |
| } | |
| // se queda por límite de tiempo. |