Skip to content

Instantly share code, notes, and snippets.

View shanehou's full-sized avatar

Shane Hou shanehou

View GitHub Profile
@shanehou
shanehou / Segment Tree.cpp
Created February 18, 2019 14:41
Segment Tree Implementation
#include <iostream>
#include <vector>
using namespace std;
int min(const int a, const int b) {
return a > b ? b : a;
}
int sum(const int a, const int b) {
return a + b;
@shanehou
shanehou / main.go
Last active April 6, 2017 13:51
一个Golang并发同步问题
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func a(i int, cs chan<- int) {
@shanehou
shanehou / react-async-script-example.js
Created May 27, 2016 15:05
react-async-script example
import React from 'react'
import ReactDOM from 'react-dom'
import makeAsyncScriptLoader from "react-async-script"
class App extends React.Component {
appendPre(message) {
const pre = document.getElementById('output')
const textContent = document.createTextNode(message + '\n')
pre.appendChild(textContent)
}
@shanehou
shanehou / alphabetical-substring.cpp
Last active March 4, 2016 13:01
Alphabetically output substrings
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
using namespace std;
void printSubstring(string s, vector<string> substrings) {
if (substrings.empty()) return;
@shanehou
shanehou / add-two-numbers.c
Created January 29, 2016 15:20
Add Two Numbers
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* addTwoNumbers(struct ListNode* l1, struct ListNode* l2) {
if (!l1) return l2;
if (!l2) return l1;
@shanehou
shanehou / multiply-strings.c
Created January 29, 2016 10:16
Multiply Strings
char* multiply(char* num1, char* num2) {
if (!num1 || !num2) return NULL;
if (num1[0] == '0' || num2[0] == '0') return "0";
int len1 = strlen(num1), len2 = strlen(num2);
if (len1 == 1 && num1[0] == '1') return num2;
if (len2 == 1 && num2[0] == '1') return num1;
char *result = malloc((len1+len2)*sizeof(char));
memset(result, '0', (len1+len2)*sizeof(char));
for (int i = len1-1; i >= 0; i--) {
int carry = 0;
@shanehou
shanehou / merge-k-sorted-lists.c
Created September 6, 2015 10:57
Merge k Sorted Lists
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define PARENT(i) (((i+1)>>1)-1)
#define LEFT(i) (((i+1)<<1)-1)
#define RIGHT(i) ((i+1)<<1)
/**
* Definition for singly-linked list.
@shanehou
shanehou / 3Sum.py
Last active August 29, 2015 14:17
看起来并没有重复,但提示Output Limit Exceeded
class Solution:
# @return a list of lists of length 3, [[val1,val2,val3]]
def threeSum(self, num):
if len(num) < 3:
return []
threes = []
countMap = dict()
for i in num:
if i in countMap:
countMap[i] += 1
@shanehou
shanehou / ant-colony.py
Last active August 29, 2015 14:02
蚁群算法,资源分配
#!/usr/bin/env python3
import random
from bisect import bisect
from itertools import accumulate
from collections import Counter
import sys
total = 180
n = 15
@shanehou
shanehou / 4chan.php
Created April 24, 2014 12:06
4chan source code duplicate
<?
if(file_exists('/www/global/lockdown')) {
if($_COOKIE['4chan_auser'] && $_COOKIE['4chan_apass'] && ($_POST['mode']=='usrdel'||$_GET['mode']=='latest')) {
// ok
}
else {
die('Posting temporarily disabled. Come back later!<br/>&mdash;Team 4chan (uptime? what\'s that?)');
}
}
include_once "./yotsuba_config.php";