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 max(v0 int, v1 int) int { | |
if v0 < v1 { | |
return v1 | |
} | |
return v0 | |
} | |
func longestUnivaluePathInternal(root *TreeNode, value int) int { | |
if nil == root || root.Val != value{ | |
return 0 |
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 isIsomorphic(s string, t string) bool { | |
if len(s) != len(t) { | |
return false | |
} | |
var pairs = make(map[uint8]uint8) | |
var reversePairs = make(map[uint8]uint8) | |
for idx := range s { | |
if v, ok := pairs[s[idx]]; ok { | |
if v != t[idx] { |
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 ( | |
"sort" | |
"fmt" | |
) | |
func threeSum(nums []int) [][]int { | |
// count elements | |
var counts = make(map[int]int) | |
for _, n := range nums { |
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
type Height struct { | |
idx int | |
value int | |
} | |
func maxArea(height []int) int { | |
var left []Height | |
for i := 0; i < len(height); i += 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
func reverse(x int) int { | |
isMinus := false | |
var remain = x | |
if 0 > x { | |
isMinus = true | |
remain = -x | |
} | |
var acc = 0 | |
for 0 < remain { |
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 ( | |
"strings" | |
"strconv" | |
) | |
func nextPermutation(nums []int) { | |
var startPoint = -1 | |
var endPoint = -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
func stringAsMinutes(timeString string) int { | |
hour := int(timeString[0] - '0') * 10 + int(timeString[1] - '0') | |
minute := int(timeString[3] - '0') * 10 + int(timeString[4] - '0') | |
return hour * 60 + minute | |
} | |
func findMinDifference(timePoints []string) int { | |
sort.Strings(timePoints) | |
lenOfTimes := len(timePoints) |
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 isToeplitzMatrix(matrix [][]int) bool { | |
for xBase := -len(matrix) + 1; xBase < len(matrix[0]); xBase++ { | |
yBase := -xBase | |
if yBase < 0 { | |
yBase = 0 | |
} | |
lastValue := matrix[yBase][xBase + yBase] | |
for y := yBase + 1; y < len(matrix) && xBase + y < len(matrix[0]); y++ { |
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
object QueueTest { | |
object Queue { | |
def empty[T]: Queue[T] = Queue[T]() | |
def queue[T](f: List[T], r: List[T]): Queue[T] = { | |
f match { | |
case Nil => | |
Queue(r.reverse, Nil) |
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
package Main | |
import java.io.{FileInputStream, FileOutputStream} | |
import scala.io.StdIn | |
object Main2 extends App { | |
Console.setIn(new FileInputStream("example2.in")) |
NewerOlder