Skip to content

Commit 381f2fa

Browse files
committed
updates
1 parent 1b13dc4 commit 381f2fa

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

226_invert_binary_tree.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Solution {
2+
def invertTree(root: TreeNode): TreeNode = {
3+
if (root == null) null
4+
else {
5+
val tmp = invertTree(root.left)
6+
root.left = invertTree(root.right)
7+
root.right = tmp
8+
root
9+
}
10+
}
11+
}

638_shopping_offers.scala

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Solution {
2+
def shoppingOffers(price: List[Int], special: List[List[Int]], needs: List[Int]): Int = {
3+
val special_filtered = special.filter(x => (x.init zip needs).map(y => y._1 <= y._2).reduce(_ && _))
4+
(special_filtered.map(x => x.last + shoppingOffers(price, special_filtered, (needs zip x.init).map(y => y._1 - y._2))) ++ List((price zip needs).map(x => x._1 * x._2).reduce(_ + _))).reduce(Math.min)
5+
}
6+
}

0 commit comments

Comments
 (0)