Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"math/rand"
"reflect"
"time"
"unsafe"
)
import "math/rand"
type Solution struct {
nums []int
init []int
}
func Constructor(nums []int) Solution {
init := make([]int,len(nums))
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
type KthLargest struct {
n []int
l int
}
func Constructor(k int, nums []int) KthLargest {
r := KthLargest{n:make([]int,k)}
for _, n := range nums {
javascript:(function()%7B(function()%7Bfunction%20getParameterByName(e%2Ct)%7Be%3De.replace(%2F%5B%5C%5B%5D%2F%2C%22%5C%5C%5B%22).replace(%2F%5B%5C%5D%5D%2F%2C%22%5C%5C%5D%22)%3Bvar%20n%3Dnew%20RegExp(%22%5B%5C%5C%3F%26%5D%22%2Be%2B%22%3D(%5B%5E%26%23%5D*)%22)%2Cr%3Dn.exec(t%3D%3Dtrue%3Flocation.hash.replace(%22%23%22%2C%22%3F%22)%3Alocation.search)%3Bif(r%3D%3Dnull%26%26t%3D%3Dfalse)%7Breturn%20getParameterByName(e%2Ctrue)%7Delse%7Breturn%20r%3D%3Dnull%3F%22%22%3AdecodeURIComponent(r%5B1%5D.replace(%2F%5C%2B%2Fg%2C%22%20%22))%7D%7Dstr%3D%22%3Cstyle%20type%3D'text%2Fcss'%3Ebody%7Bcolor%3A%23000%3Bbackground-color%3A%23fff%3Bmargin%3A0%3Bpadding%3A0%3Bfont-family%3Aarial%2Chelvetica%2Csans-serif%3Bfont-size%3A82%25%7D*%7Bfont-weight%3A400%3Bcolor%3A%23000%7Dh3%2Ch4%2Ch5%2Ch6%7Bmargin%3A0%200%2015px%3Bpadding%3A0%7D%23rt%7Bfont-size%3A12px%3Bwidth%3A500px%7Dtable%2Ctd%2Cth%2Ctr%7Bfont-size%3A1em%3Boverflow%3Ahidden%3Btext-overflow%3Aellipsis%3Bword-wrap%3Abreak-word%7Dtextarea%7Bwidth%3A100%25%7Dth%7Bbackground
#include <iostream>
#include <cmath>
#include <cstring>
#include <map>
#include <memory>
#include <vector>
#include <set>
#include <ctime>
#include <chrono>
#include <iostream>
#include <cmath>
#include <cstring>
#include <map>
#include <assert.h>
#include <memory>
#include <vector>
#include <set>
#include <ctime>
#include <chrono>
scala> def addToFirst[T<:Int](x:Array[T]) = x(0)
addToFirst: [T <: Int](x: Array[T])T
scala> addToFirst(Array(19))
res32: Int = 19
-------------------------------------------------------
scala> def addToFirst(x : Array[T] forSome {type T <: Integer}) = x(0)
addToFirst: (x: Array[_ <: Integer])Int
scala> trait A
defined trait A
scala> class A1 extends A;
defined class A1
scala> class A2 extends A;
defined class A2
scala> def addToFirst[T<:A](x:Array[T]) = x(0)
addToFirst: [T <: A](x: Array[T])T
def toJSON[T](o: T)(implicit tjs: Writes[T]): JsValue = tjs.writes(o)
implicit object w2 extends Writes[Document] {
def writes(o: Document) = {
JsObject(o.toMap.map {
x =>
// def implicitly[T](implicit e: T): T = e
val v = toJSON(x._2)
( x._1.toString,v )
})