Skip to content

Instantly share code, notes, and snippets.

def atMostNGivenDigitSet(digits: Array[String], n: Int): Int = {
val sorted = digits.map(_.toInt).sorted
val maxPow = math.log10(n).toInt
def atMostNGivenDigitSet(sorted: Array[Int], pow: Int = 0): collection.mutable.Set[Int] = {
if (pow > maxPow) return collection.mutable.Set()
val digitSet = collection.mutable.Set[Int]()
for (digit <- sorted) {
def findLettersOrDigits(chars: Array[Char], i: Int, f: Char => Boolean): String = {
if (i == chars.length) return ""
val char = chars(i)
if (f(char)) {
char.toString + findLettersOrDigits(chars, i + 1, f)
}
else {
""
def connect(root: Node): Node = {
def connectEdges(left: Node, right: Node): Unit = {
if (left == null) return
println(left.value)
left.next = right
connectEdges(left.right, right.left)
}
object Solution {
def flipAndInvertImage(A: Array[Array[Int]]): Array[Array[Int]] = {
for {row <- A} yield row.reverse.map(_^1)
}
}
def maxAncestorDiff(root: TreeNode): Int = {
def visit(node: TreeNode, min: Int, max: Int): Int = {
if (node == null) return 0
val diff = math.max(math.abs(node.value - max), math.abs(node.value - min))
val newMin = math.min(node.value, min)
val newMax = math.max(node.value, max)
math.max(math.max(diff, visit(node.left, newMin, newMax)), visit(node.right, newMin, newMax))
}
### Keybase proof
I hereby claim:
* I am brunofarache on github.
* I am brunofarache (https://keybase.io/brunofarache) on keybase.
* I have a public key ASCZktYBXeojNUooIaGEjYtQ5kjKAa57RtVwsYqq-ZpxSAo
To claim this, I am signing this object:
@brunofarache
brunofarache / pre-push.sh
Last active August 15, 2019 01:56
git pre-push hook that prevents sending pull requests without green yarn tests
remote="$1"
url="$2"
folder="modules/private/apps/portal-workflow/portal-workflow-metrics-web"
origin="origin"
if [[ $remote != $origin ]]; then
exit 0
fi
cd $folder
@brunofarache
brunofarache / .travis.yml
Last active November 28, 2017 21:31
xamarin travis image proposal with default values
os: osx
language: xamarin
solution: solution-name
mono:
mdk: 4.6.2
android: 7.0.2-42
ios: 10.3.1.8
android:
@brunofarache
brunofarache / curl.txt
Last active October 29, 2015 14:37
curl
curl https://loop-uat.liferay.com/api/jsonws/loop-portlet.feed/viewMyNewFeed \
-u bruno.farache@liferay.com:weloveliferay \
-d assetTagNames= \
-d childAssetEntrySetsLimit=1 \
-d end=1 \
-d likedParticipantsLimit=1 \
-d modifiedTime=0 \
-d parentAssetEntrySetId=0 \
-d start=0
Launchpad
.url("http://liferay.io/todo/tasks/items")
.param("checked", true)
.param("description", "Organize DevCon 2015")
.param("name", "Ruth Heil")
.post()
.then { response in
XCTAssertTrue(response.succeeded)
}
.done()