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
func romanToInt(s string) int { | |
romanNums := map[byte]int{ | |
'I': 1, | |
'V': 5, | |
'X': 10, | |
'L': 50, | |
'C': 100, | |
'D': 500, | |
'M': 1000, | |
} |
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
func findMedianSortedArrays(nums1 []int, nums2 []int) float64 { | |
p1l, p1r := 0, len(nums1) | |
p2l, p2r := 0, len(nums2) | |
m := float64(p1r+p2r-1) / 2 | |
for i := int(m); i > 0; i-- { | |
if p1l == p1r { | |
p2l++ | |
} else if p2l == p2r { |
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[]} height | |
* @return {number} | |
* | |
* O(n) time | |
* O(1) space | |
*/ | |
function maxArea(height) { | |
let max = 0; | |
let i = 0; |
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} digits | |
* @return {string[]} | |
*/ | |
const letterCombinations = function(digits) { | |
if (digits.length === 0) return []; | |
const map = { | |
"2": ["a", "b", "c"], | |
"3": ["d", "e", "f"], |
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} l1 | |
* @param {ListNode} l2 |
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 isValid = function(s) { | |
const par = { | |
"(": ")", | |
"{": "}", | |
"[": "]", |
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[]} gas | |
* @param {number[]} cost | |
* @return {number} | |
*/ | |
var canCompleteCircuit = function(gas, cost) { | |
if(gas.length==0){ | |
return -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} x | |
* @return {boolean} | |
*/ | |
const isPalindrome = x => { | |
if (x < 0) return false | |
let reverse = 0, y = x | |
while (y > 0) { | |
const lastNumber = y % 10 |