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
<?php | |
function weight($arr) { | |
if(count($arr) == 1) { | |
return array_keys($arr)[0]; | |
} | |
$size = count($arr)/3; | |
$a = array_slice($arr, 0, $size, true); | |
$b = array_slice($arr, $size, $size, true); | |
if(($sumA = array_sum($a)) == ($sumB = array_sum($b))) { | |
return weight(array_slice($arr, $size*2, null, true)); |
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[]} numbers | |
* @param {number} target | |
* @return {number[]} two integers in an array, ie: [index1, index2] | |
*/ | |
var twoSum = function(numbers, target) { | |
var max = numbers.length, map = {}; | |
for(var i = 0; i < max; i++) { | |
if(map[numbers[i]] !== undefined) { | |
return [map[numbers[i]]+1, i+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
var http = require('http'), | |
https = require('https'), | |
URL = require('url'); | |
var request = function(name, url, proxy) { | |
// options | |
var options = URL.parse(url, false); | |
// headers | |
options.headers = { | |
accept: '*/*', |