mirror of https://github.com/01-edu/public.git
Xavier Petit
5 years ago
committed by
xpetit
55 changed files with 397 additions and 360 deletions
@ -1,23 +1,23 @@
|
||||
package solutions |
||||
|
||||
type TNode struct { |
||||
Val int |
||||
Left *TNode |
||||
Right *TNode |
||||
Val int |
||||
Left *TNode |
||||
Right *TNode |
||||
} |
||||
|
||||
func Invert(root *TNode) { |
||||
if root != nil { |
||||
temp := root.Left |
||||
root.Left = root.Right |
||||
root.Right = temp |
||||
if root != nil { |
||||
temp := root.Left |
||||
root.Left = root.Right |
||||
root.Right = temp |
||||
|
||||
Invert(root.Left) |
||||
Invert(root.Right) |
||||
} |
||||
Invert(root.Left) |
||||
Invert(root.Right) |
||||
} |
||||
} |
||||
|
||||
func InvertTree(root *TNode) *TNode { |
||||
Invert(root) |
||||
return root |
||||
Invert(root) |
||||
return root |
||||
} |
||||
|
@ -1,19 +1,19 @@
|
||||
package solutions |
||||
|
||||
//This solution is the comparing file of the staff
|
||||
// Because the solution is a function,
|
||||
// This solution is the comparing file of the staff
|
||||
// Because the solution is a function,
|
||||
//
|
||||
//1) here the package is solutions
|
||||
//2) it does not need an empty func main(){}
|
||||
//3) its location is 1 level below the folder of the nauuo_test.go file
|
||||
// 1) here the package is solutions
|
||||
// 2) it does not need an empty func main(){}
|
||||
// 3) its location is 1 level below the folder of the nauuo_test.go file
|
||||
|
||||
func gcd(first, second int) int { |
||||
if (second == 0) { |
||||
return (first) |
||||
if second == 0 { |
||||
return first |
||||
} |
||||
return (gcd(second, first % second)) |
||||
return gcd(second, first%second) |
||||
} |
||||
|
||||
func Lcm(first, second int) int { |
||||
return (first / gcd(second, first % second) * second) |
||||
} |
||||
return first / gcd(second, first%second) * second |
||||
} |
||||
|
@ -1,27 +1,27 @@
|
||||
package solutions |
||||
|
||||
type TreeNodeL struct { |
||||
Left *TreeNodeL |
||||
Val int |
||||
Right *TreeNodeL |
||||
Left *TreeNodeL |
||||
Val int |
||||
Right *TreeNodeL |
||||
} |
||||
|
||||
func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { |
||||
if (p == nil && q == nil) { |
||||
return true |
||||
} |
||||
if (checkIfEq(p, q) == true) { |
||||
return true |
||||
} |
||||
return false |
||||
if p == nil && q == nil { |
||||
return true |
||||
} |
||||
if checkIfEq(p, q) == true { |
||||
return true |
||||
} |
||||
return false |
||||
} |
||||
|
||||
func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool { |
||||
if (t1 == nil && t2 == nil) { |
||||
return true |
||||
} |
||||
if (t1 == nil || t2 == nil) { |
||||
return false; |
||||
} |
||||
return (t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)) |
||||
if t1 == nil && t2 == nil { |
||||
return true |
||||
} |
||||
if t1 == nil || t2 == nil { |
||||
return false |
||||
} |
||||
return (t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)) |
||||
} |
||||
|
@ -1,31 +1,31 @@
|
||||
package main |
||||
|
||||
type TreeNodeL struct { |
||||
Left *TreeNodeL |
||||
Val int |
||||
Right *TreeNodeL |
||||
Left *TreeNodeL |
||||
Val int |
||||
Right *TreeNodeL |
||||
} |
||||
|
||||
func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool { |
||||
if (p == nil && q == nil) { |
||||
return true |
||||
} |
||||
if (checkIfEq(p, q) == true) { |
||||
return true |
||||
} |
||||
return false |
||||
if p == nil && q == nil { |
||||
return true |
||||
} |
||||
if checkIfEq(p, q) == true { |
||||
return true |
||||
} |
||||
return false |
||||
} |
||||
|
||||
func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool { |
||||
if (t1 == nil && t2 == nil) { |
||||
return true |
||||
} |
||||
if (t1 == nil || t2 == nil) { |
||||
return false; |
||||
} |
||||
return (t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)) |
||||
if t1 == nil && t2 == nil { |
||||
return true |
||||
} |
||||
if t1 == nil || t2 == nil { |
||||
return false |
||||
} |
||||
return (t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)) |
||||
} |
||||
|
||||
func main() { |
||||
|
||||
} |
||||
|
||||
} |
||||
|
@ -1,17 +1,17 @@
|
||||
package main |
||||
|
||||
import ( |
||||
"math/rand" |
||||
"math/rand" |
||||
"testing" |
||||
|
||||
"github.com/01-edu/z01" |
||||
solutions "../../solutions" |
||||
"github.com/01-edu/z01" |
||||
) |
||||
|
||||
func TestTwoSum(t *testing.T) { |
||||
for i := 0; i < 20; i++ { |
||||
token := rand.Perm(20) |
||||
target := rand.Intn(30) |
||||
z01.Challenge(t, TwoSum, solutions.TwoSum, token, target) |
||||
} |
||||
for i := 0; i < 20; i++ { |
||||
token := rand.Perm(20) |
||||
target := rand.Intn(30) |
||||
z01.Challenge(t, TwoSum, solutions.TwoSum, token, target) |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue