Skip to content

Instantly share code, notes, and snippets.

View nleiva's full-sized avatar
☠️
Working from somewhere

Nicolas Leiva nleiva

☠️
Working from somewhere
View GitHub Profile
@nleiva
nleiva / shrange.go
Created February 28, 2018 21:00
SHORTEST RANGE IN K SORTED LISTS from https://www.youtube.com/watch?v=zplklOy7ENo, first take (not optimal)
package main
import (
"fmt"
"sort"
)
type Slice []int
func (a Slice) Len() int { return len(a) }
@nleiva
nleiva / combinations.go
Created February 26, 2018 21:16
Combinations (77) from https://leetcode.com/problems/combinations/description/ ....too compex :-(
// Slice implements sort.Interface
type Slice []int
func (a Slice) Len() int { return len(a) }
func (a Slice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Slice) Less(i, j int) bool { return a[i] < a[j] }
func combine(n int, k int) [][]int {
a := []int{}
for i := 1; i <= n; i++ {
func findMaxConsecutiveOnes(nums []int) int {
total := 0
max := 0
for i := 0; i < len(nums); i++ {
if nums[i] == 1 {
total++
if total > max {
max = total
}
} else {