This file contains hidden or 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
class TrieNode: | |
def __init__(self, c: str, path: str): | |
self.c = c # type: str | |
self.counter = 0 # type: str | |
self.path = path # type: str | |
self.children = dict() # type: Dict[str, TrieNode] | |
def add(self, key: str, path: str): | |
if len(key) == 0: | |
self.counter += 1 |
This file contains hidden or 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
class Solution: | |
def generateMatrix(self, n: int) -> List[List[int]]: | |
if n == 1: | |
return [[1]] | |
mat = [[0 for i in range(n)] for j in range(n)] | |
counter = 1 | |
for i in range(0, n): | |
x, y = i, i | |
width = n - i * 2 | |
height = width - 2 |
This file contains hidden or 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 heapq | |
class Solution: | |
def twoCitySchedCost(self, costs: List[List[int]]) -> int: | |
heap = [] | |
for cost in costs: | |
heapq.heappush(heap, (-abs(cost[0] - cost[1]), cost[0], cost[1])) | |
N = len(costs) / 2 | |
total = 0 |
This file contains hidden or 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
class Solution: | |
def pruneTree(self, root: TreeNode) -> TreeNode: | |
if root == None: | |
return None | |
left = self.pruneTree(root.left) | |
right = self.pruneTree(root.right) | |
if root.val == 1 or left or right: # not prunable | |
root = TreeNode(root.val) | |
root.left = left | |
root.right = right |
This file contains hidden or 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 cats._ | |
import cats.implicits._ | |
import cats.effect._ | |
import scala.concurrent.duration._ | |
object ProcessIO { | |
import scala.sys.process._ | |
def exec[F[_]](commands: String)(implicit F: ConcurrentEffect[F], T: Timer[F]): F[Unit] = { | |
def acquire: F[Process] = F.delay(commands.run()) |
This file contains hidden or 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
val doobieVersion = "0.6.0" | |
import $ivy.`org.tpolecat:doobie-core_2.12:0.6.0` | |
import $ivy.`org.tpolecat:doobie-postgres_2.12:0.6.0` | |
import $ivy.`org.tpolecat:doobie-specs2_2.12:0.6.0` | |
import doobie._ | |
import doobie.implicits._ | |
import cats._ | |
import cats.data._ | |
import cats.effect.IO | |
import cats.implicits._ |
This file contains hidden or 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
public ListNode reverseList(ListNode head) { | |
if (head == null) return head; | |
ListNode curr = head.next; | |
head.next = null; | |
while (curr != null) { | |
ListNode next = curr.next; | |
curr.next = head; | |
head = curr; | |
curr = next; |
This file contains hidden or 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
// Copyright(C) 2018 - John A. De Goes. All rights reserved. | |
package net.degoes.abstractions | |
import scalaz._ | |
import Scalaz._ | |
import scala.language.higherKinds | |
object algebra { |
This file contains hidden or 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
// Copyright(C) 2018 - John A. De Goes. All rights reserved. | |
package net.degoes.essentials | |
import java.time.{Instant, ZonedDateTime} | |
import scala.util.Try | |
object types { | |
type ??? = Nothing |
This file contains hidden or 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
// Copyright(C) 2018 - John A. De Goes. All rights reserved. | |
package net.degoes.effects | |
import scalaz.zio._ | |
import scalaz.zio.console._ | |
import scala.annotation.tailrec | |
import scala.concurrent.duration._ |
NewerOlder