Skip to content

Instantly share code, notes, and snippets.

View alldroll's full-sized avatar

Aleksandr Petrov alldroll

View GitHub Profile
func angleClock(hour int, minutes int) float64 {
left, right := hourAngle(hour, minutes), minuteAngle(minutes)
if left < right {
right, left = left, right
}
return min(left - right, 360 - left + right)
}
import "container/heap"
type HeapItem struct {
val int
index int
}
type Heap []HeapItem
func (h Heap) Len() int { return len(h) }
import "container/heap"
type HeapItem struct {
value int
listID int
}
type Heap []HeapItem
func (h Heap) Len() int { return len(h) }
/**
* Definition for a Node.
* type Node struct {
* Val int
* Left *Node
* Right *Node
* Next *Node
* }
*/
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
type LevelNode struct {
const (
water = 0
land = 1
visited = 2
)
var directions = [][2]int{
{0, 1},
{1, 0},
{0, -1},
const (
playerNone = 0
playerA = 1
playerB = 2
)
type line struct {
count int
player int
}
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* }
*/
/**
* Definition for a binary tree node.
* type TreeNode struct {
import "container/heap"
type Item struct {
word string
count int
}
func (i Item) Less(o Item) bool {
if i.count == o.count {
return i.word > o.word
func nextGreaterElement(nums1 []int, nums2 []int) []int {
stack := []int{}
table := make(map[int]int)
for _, num := range nums2 {
for len(stack) > 0 && stack[len(stack) - 1] < num {
item := stack[len(stack) - 1]
stack = stack[:len(stack) - 1]
table[item] = num
}