Skip to content

Instantly share code, notes, and snippets.

View aire-con-gas's full-sized avatar

Dave Hong aire-con-gas

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@aire-con-gas
aire-con-gas / num_of_islands.js
Last active March 8, 2019 13:39
num_of_islands.js
function dfs(grid, r, c) {
var nr = grid.length;
var nc = grid[0].length;
if (r < 0 || c < 0 || r >= nr || c >= nc || grid[r][c] === '0') {
return;
}
grid[r][c] = '0';
dfs(grid, r - 1, c);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
/*
public boolean isHappy(int n) {
int x = n;
int y = n;
while(x>1){
x = cal(x) ;
if(x==1) return true ;
y = cal(cal(y));
if(y==1) return true ;
/**
*/
"use strict";
var threeSumClosest = function threeSumClosest(num, target) {
var result = num[0] + num[1] + num[num.length - 1];
num.sort();
for (var i = 0, il = num.length - 2; i < il; i++) {
var start = i + 1;
var end = num.length - 1;
/**
* @param {string[]} strs
* @return {string}
*/
var longestCommonPrefix = function(strs) {
// initialize matches found map
var matchesFound = {};
var commonPrefix = '';
var lastMatchedPrefix;
var matchesFoundKeys;
/**
* @param {string} s
* @return {number}
*/
var romanToInt = function(s) {
// make a map of chars
var romanNumMap = {
'I': 1,
'V': 5,
'X': 10,
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
'use strict';
function atoi(str) {
var sign = 1;
var base = 0;
var i = 0;
var INT_MIN = Number.MIN_VALUE;
var INT_MAX = Number.MAX_VALUE;
var strArr = str.split('');
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">