Skip to content

Instantly share code, notes, and snippets.

View jmichelin's full-sized avatar
💭
Woot!

JohnMichelin jmichelin

💭
Woot!
View GitHub Profile

Prompt

Given an array a that contains only numbers in the range from 1 to a.length, find the first duplicate number. (See examples below to see what we mean here by the "first" duplicate).

If there are no such elements, return -1.

Note: Your solution should be O(n) runtime and O(1) space.

Examples

@jmichelin
jmichelin / has-path-sum.js
Last active January 16, 2018 05:41
Reference solution for hasPathSum
const hasPathSum = function(node, targetSum) {
if (!node) return targetSum === 0;
targetSum -= node.val;
return hasPathSum(node.left, targetSum) || hasPathSum(node.right, targetSum);
};
/*
const root = {
// .babelrc
{
"presets": ["es2015", "react"]
}
package org.sdo.alg.other
/**
* Created by dsemenov
* Date: 1/7/16.
*/
trait WaterCollect {
def collectWater(towers: List[Int]): Int = {
def walkMax(towers: List[Int]): List[Int] = {
var tempMax = 0
@jmichelin
jmichelin / .bash_profile
Created January 22, 2016 03:55 — forked from natelandau/.bash_profile
Mac OSX Bash Profile
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@jmichelin
jmichelin / bash_profile.sh
Created January 1, 2016 01:43 — forked from dtateii/bash_profile.sh
Bash Profile [Nate Landau]
# ht: http://natelandau.com/my-mac-osx-bash_profile/
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching