Skip to content

Instantly share code, notes, and snippets.

Lucas Guigui MichaelScofield

Block or report user

Report or block MichaelScofield

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Main.java
import org.apache.commons.lang3.tuple.Pair;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
//noinspection unchecked
Pair<String, Boolean>[] testCases = new Pair[]{
Pair.of("ex 1", true),
Pair.of("px 1", true),
@MichaelScofield
MichaelScofield / leetcode_solution_538.go
Created Sep 14, 2017
538. Convert BST to Greater Tree
View leetcode_solution_538.go
var sum int
func convertBST(root *TreeNode) *TreeNode {
if root == nil {
return nil
}
sum = 0
traverse(root)
@MichaelScofield
MichaelScofield / ClhSpinLock.java
Last active Aug 29, 2015
A simple CLH spin lock implementation
View ClhSpinLock.java
public class ClhSpinLock {
private final ThreadLocal<Node> pred;
private final ThreadLocal<Node> node;
private final AtomicReference<Node> tail = new AtomicReference<Node>(new Node());
public ClhSpinLock() {
node = new ThreadLocal<Node>() {
protected Node initialValue() {
return new Node();
}
@MichaelScofield
MichaelScofield / JavaWaitAndNotify
Created May 7, 2013
Typical usage of Object.wait() and Object.notify()
View JavaWaitAndNotify
package test;
public class Main {
private final Object MONITOR = new Object();
private class PrintNum extends Thread {
volatile int num = 1;
@MichaelScofield
MichaelScofield / PELargestPrimeFactor.java
Last active Dec 11, 2015
ProjectEuler.net: Problem 3, My solution. Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?
View PELargestPrimeFactor.java
import java.util.Arrays;
import java.util.TreeSet;
public class Test {
public TreeSet<Long> results = new TreeSet<Long>();
// see http://en.wikipedia.org/wiki/Fermat's_factorization_method
public long[] fermatFactor(long n) {
long[] result = new long[2];
@MichaelScofield
MichaelScofield / PESmallestMultiple.java
Last active Jan 30, 2018
ProjectEuler.net <My solution> Problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
View PESmallestMultiple.java
public static void main(String[] args) {
long result = 1;
int upLimit = 20;
Set<Integer> digits = new HashSet<Integer>();
for (int i = 1; i <= upLimit; i++) {
if (result % i != 0) {
digits.add(i);
result *= i;
for (int j = 2; j < i; j++) {
if (i % j == 0 && result % j == 0) {
You can’t perform that action at this time.