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
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 |
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
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 本书)所花时间 | |
) |
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
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) |
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
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 |
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
0 1 2 | |
R | |
B | |
G | |
R | |
B | |
B | |
//http://buttercola.blogspot.com/2015/09/leetcode-paint-house-ii.html |
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
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)); |
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
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; |
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
package main | |
import ( | |
"fmt" | |
) | |
// X O O X X X | |
func main() { | |
//var arr [6]int = [6]int{0,1,1,0,0,0} |
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
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. |
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
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: |