feat: osijvrsoi
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package count_paths_that_can_form_a_palindrome_in_a_tree
|
||||
|
||||
func isPalindromable(s string) bool {
|
||||
set := map[rune]int{}
|
||||
|
||||
for _, b := range s {
|
||||
set[b]++
|
||||
}
|
||||
|
||||
singletons := 0
|
||||
for _, v := range set {
|
||||
switch v {
|
||||
case 1:
|
||||
singletons++
|
||||
case 2:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return singletons < 2
|
||||
}
|
||||
|
||||
func CountPalindromePaths(parent []int, s string) int64 {
|
||||
return 0
|
||||
}
|
||||
53
pkg/questions/course_schedule/main.go
Normal file
53
pkg/questions/course_schedule/main.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package courseschedule
|
||||
|
||||
func visit(prereqs map[int][]int, temporary map[int]bool, permanent map[int]bool, class int) bool {
|
||||
if temporary[class] {
|
||||
return false
|
||||
}
|
||||
if permanent[class] {
|
||||
return true
|
||||
}
|
||||
|
||||
if _, ok := prereqs[class]; !ok {
|
||||
return true
|
||||
}
|
||||
|
||||
temporary[class] = true
|
||||
|
||||
for _, p := range prereqs[class] {
|
||||
if !visit(prereqs, temporary, permanent, p) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
permanent[class] = true
|
||||
temporary[class] = false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func canFinish(numCourses int, prerequisites [][]int) bool {
|
||||
prereqs := map[int][]int{}
|
||||
for _, p := range prerequisites {
|
||||
class, prerequisite := p[0], p[1]
|
||||
|
||||
if _, ok := prereqs[class]; !ok {
|
||||
prereqs[class] = []int{}
|
||||
}
|
||||
|
||||
prereqs[class] = append(prereqs[class], prerequisite)
|
||||
}
|
||||
|
||||
temporary, permanent := map[int]bool{}, map[int]bool{}
|
||||
for c := range prereqs {
|
||||
if permanent[c] {
|
||||
continue
|
||||
}
|
||||
|
||||
if !visit(prereqs, temporary, permanent, c) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
57
pkg/tools/list/main.go
Normal file
57
pkg/tools/list/main.go
Normal file
@@ -0,0 +1,57 @@
|
||||
package tools
|
||||
|
||||
type Node[T any] struct {
|
||||
value T
|
||||
before *Node[T]
|
||||
after *Node[T]
|
||||
}
|
||||
|
||||
type List[T any] struct {
|
||||
front *Node[T]
|
||||
back *Node[T]
|
||||
size uint
|
||||
}
|
||||
|
||||
func New[T any]() List[T] {
|
||||
return List[T]{nil, nil, 0}
|
||||
}
|
||||
|
||||
func (l *List[T]) PushFront(t T) {
|
||||
item := &Node[T]{t, nil, nil}
|
||||
|
||||
if l.back == nil {
|
||||
l.back = item
|
||||
}
|
||||
|
||||
if front := l.front; front != nil {
|
||||
front.before, item.after = item, front
|
||||
}
|
||||
|
||||
l.size++
|
||||
l.front = item
|
||||
}
|
||||
|
||||
func (l *List[T]) PopBack() (result T, good bool) {
|
||||
if l.back == nil {
|
||||
return
|
||||
}
|
||||
|
||||
result = l.back.value
|
||||
good = true
|
||||
|
||||
if l.front == l.back {
|
||||
l.front = nil
|
||||
}
|
||||
|
||||
if before := l.back.before; before != nil {
|
||||
before.after = nil
|
||||
}
|
||||
|
||||
l.size--
|
||||
l.back = l.back.before
|
||||
return
|
||||
}
|
||||
|
||||
func (l *List[T]) Size() uint {
|
||||
return l.size
|
||||
}
|
||||
Reference in New Issue
Block a user