Skip to content

Instantly share code, notes, and snippets.

Avatar

Khoa Le khoatle

  • Microsoft @Azure
  • Redmond, WA
View GitHub Profile
@khoatle
khoatle / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@khoatle
khoatle / longest.cpp
Created May 20, 2013
Given two input texts, find the longest string that occurs in both.
View longest.cpp
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
string longest_in_both(const string& s1, const string& s2) {
vector<vector<int> > dp;
for(int i = 0; i < s1.length(); i++) {
dp.push_back(vector<int>(s2.length(), -1));
View DNASorting.java
import java.util.*;
public class DNASorting {
public static class DNA implements Comparable {
String dna;
public DNA(String str) {
dna = str;
}
View Yeehaa.java
import java.util.Scanner;
public class Yeehaa {
public double findr(double R, int N) {
double theta = Math.PI * 2 / N;
double b = Math.sqrt(R * R + R * R - 2 * R * R * Math.cos(theta));
return b * R / (b + 2 * R);
}
@khoatle
khoatle / GeneratePalindrome.java
Created Apr 14, 2013
Generate a palindrome sequence of size N
View GeneratePalindrome.java
import java.util.*;
public class GeneratePalindrome {
public static List<String> palindromesOfLength(int N, Set<String> alphabet) {
List<String> result = new ArrayList<String>();
if(N == 1) {
for(String letter : alphabet) {
result.add(letter);
}
View AlienLanguage.java
import java.util.*;
public class AlienLanguage {
private static class Token {
Set<Character> validChars = new HashSet<Character>();
public Token(String string) {
for(int i = 0; i < string.length(); i++) {