Skip to content

Instantly share code, notes, and snippets.

https://discuss.leetcode.com/topic/92873/c-java-clean-code-priority-queue
https://discuss.leetcode.com/topic/92852/concise-java-solution-o-n-time-o-26-space
A Queue : 2 -> 2 -> 1
B Queue : 3 -> 2
C Queue : 4 -> 3
n=2;
Array
@cc2011
cc2011 / gist:bc3f1639c2faef4030a8c14bd60f567d
Last active August 16, 2017 07:19
copy books and split-array-largest-sum
https://leetcode.com/problems/split-array-largest-sum/description/
f[k][i] = min{max{f[k-1][j], A[j] +…+A[i-1]}}
f[k][i] : 前k个人抄0到i本书
Max(
前k-1个人抄 0-j本书 最少用的时间,
最后一个人抄剩下的书(j+1 => i 本书)所花时间
)
https://leetcode.com/problems/set-mismatch/description/
1 2 2 4
sum = n*(n+1)/2 = 10
10-1=9
9-2=7
7-2=5 (2)
5-4=(1)
http://buttercola.blogspot.com/2015/09/leetcode-paint-house-ii.html
public class Solution {
/*
public int minCostII(int[][] costs) {
if(costs == null || costs.length == 0)
return 0;
int n = costs.length;
int m = costs[0].length;
int[][] dp = new int[n][m];
//initialization
0 1 2
R
B
G
R
B
B
//http://buttercola.blogspot.com/2015/09/leetcode-paint-house-ii.html
import java.io.*;
import java.util.*;
class Solution {
public static void main(String[] args) {
Solution soln = new Solution();
System.out.println(soln.numberOfPatterns(2,3));
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
@cc2011
cc2011 / gist:030836fdd42cf5d047a507da91b4bd96
Created June 12, 2016 03:18
Num of Trucks (Repair road question)
package main
import (
"fmt"
)
// X O O X X X
func main() {
//var arr [6]int = [6]int{0,1,1,0,0,0}
func hypot(x, y float64) float64 {
return math.Sqrt(x*x + y*y)
}
fmt.Println(hypot(3, 4)) // "5"
x and y are parameters in the declaration, 3 and 4 are arguments of the call, and the function returns a float64 value.
Arguments are passed by value, so the function receives a copy of each argument;
modifica- tions to the copy do not affect the caller. However, if the argument contains some kind of ref- erence,
like a pointer, slice, map, function, or channel, then the caller may be affected by any modifications the function
makes to variables indirectly referred to by the argument.
Two ways to initialize struct
=============================
First Form
===========
type Point struct{ X, Y int }
p := Point{1, 2}
Second Form
===========
The second form is used, in which a struct value is initialized by listing some or all of the field names and their corresponding values, as in this statement from the Lissajous program of Section 1.4: