Skip to content

Instantly share code, notes, and snippets.

View cbdavide's full-sized avatar

David Castelblanco cbdavide

View GitHub Profile
@cbdavide
cbdavide / BinarySearch.js
Last active April 30, 2022 02:18
Binary search algorithm in javascript
var binarySearch = function(array, value) {
var guess,
min = 0,
max = array.length - 1;
while(min <= max){
guess = Math.floor((min + max) /2);
if(array[guess] === value)
return guess;
else if(array[guess] < value)
@cbdavide
cbdavide / SelectionSort.js
Created May 12, 2016 02:29
Selection sort algorithm in javascript
var selectionSort = function(array) {
var temp;
for(var i=0; i<array.length; i++){
var mi = i;
for(var j = i + 1; j<array.length; j++) {
if(array[j] < array[mi])
mi = j;
}
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def mergeKLists(self, lists: List[ListNode]) -> ListNode:
self.lists = lists
@cbdavide
cbdavide / 10622.cpp
Created February 14, 2019 01:16
UVa - 10622 - Perfect P-th Powers
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define PB push_back
typedef long long ll;
typedef vector<ll> vll;
@cbdavide
cbdavide / 583.cpp
Created February 5, 2019 00:08
UVa 583 - Prime Factors
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define PB push_back
typedef long long ll;
typedef vector<ll> vll;
@cbdavide
cbdavide / 10819.cpp
Created January 25, 2019 03:12
UVa 10819 - Trouble of 13-Dots
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define PB push_back
typedef long long ll;
typedef vector<ll> vll;
@cbdavide
cbdavide / 128.cpp
Created January 25, 2019 03:09
UVa 128 - Software CRC
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define PB push_back
typedef long long ll;
typedef vector<ll> vll;
@cbdavide
cbdavide / 10003.cpp
Created January 24, 2019 00:26
UVa - 10003 - Cutting Sticks
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define PB push_back
typedef long long ll;
typedef vector<ll> vll;
@cbdavide
cbdavide / 10126.cpp
Created January 20, 2019 17:21
UVa 10126 - Zipf's Law
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define PB push_back
typedef long long ll;
typedef vector<ll> vll;
@cbdavide
cbdavide / 10149.cpp
Created January 20, 2019 17:19
UVa 10149 - Yahtzee
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
#define PB push_back
typedef long long ll;
typedef vector<ll> vll;