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 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) | |
} |
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 "container/heap" | |
type HeapItem struct { | |
val int | |
index int | |
} | |
type Heap []HeapItem | |
func (h Heap) Len() int { return len(h) } |
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 "container/heap" | |
type HeapItem struct { | |
value int | |
listID int | |
} | |
type Heap []HeapItem | |
func (h Heap) Len() int { return len(h) } |
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
/** | |
* Definition for a Node. | |
* type Node struct { | |
* Val int | |
* Left *Node | |
* Right *Node | |
* Next *Node | |
* } | |
*/ |
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
/** | |
* Definition for a binary tree node. | |
* type TreeNode struct { | |
* Val int | |
* Left *TreeNode | |
* Right *TreeNode | |
* } | |
*/ | |
type LevelNode struct { |
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
const ( | |
water = 0 | |
land = 1 | |
visited = 2 | |
) | |
var directions = [][2]int{ | |
{0, 1}, | |
{1, 0}, | |
{0, -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
const ( | |
playerNone = 0 | |
playerA = 1 | |
playerB = 2 | |
) | |
type line struct { | |
count int | |
player int | |
} |
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
/** | |
* Definition for singly-linked list. | |
* type ListNode struct { | |
* Val int | |
* Next *ListNode | |
* } | |
*/ | |
/** | |
* Definition for a binary tree node. | |
* type TreeNode struct { |
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 "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 |
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 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 | |
} |
NewerOlder