File tree Expand file tree Collapse file tree 4 files changed +33
-1
lines changed
main/scala/org/codecraftlabs/leetcode
test/scala/org/codecraftlabs/leetcode Expand file tree Collapse file tree 4 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,11 @@ to keep up with the language and learn how to use the Scala test library as well
3434* Add binary
3535* Contains duplicate
3636* Middle of linked list
37+ * Jewels and stones
3738
3839## Versions
40+ * v1.0.21.0 (10/07/2018) - Added Jewels and stones exercise.
41+
3942* v1.0.20.2 (10/06/2018) - Improved null argument handling for Middle of linked list exercise.
4043
4144* v1.0.20.1 (10/06/2018) - Improved null argument handling for Contains duplicate exercise.
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ lazy val root = (project in file(".")).
55 inThisBuild(List (
66 organization := " org.codecraftlabs" ,
77 scalaVersion := " 2.12.7" ,
8- version := " 1.0.20.2 "
8+ version := " 1.0.21.0 "
99 )),
1010 name := " leetcode-scala" ,
1111 libraryDependencies += scalaTest % Test ,
Original file line number Diff line number Diff line change 1+ package org .codecraftlabs .leetcode
2+
3+ object JewelsAndStones {
4+ def numJewelsInStones (j : String , s : String ): Int = {
5+ val jewels = j.toSet
6+ val stones = s.toList
7+
8+ val groupedStones = stones.groupBy(identity).mapValues(_.length)
9+ groupedStones.filterKeys(jewels).values.sum
10+ }
11+ }
Original file line number Diff line number Diff line change 1+ package org .codecraftlabs .leetcode
2+
3+ import org .codecraftlabs .leetcode .JewelsAndStones .numJewelsInStones
4+ import org .scalatest .{FlatSpec , Matchers }
5+
6+ class JewelsAndStonesSpec extends FlatSpec with Matchers {
7+ it should " return 3 with jewels = 'aA' and stones = 'aAAbbbb'" in {
8+ val jewels = " aA"
9+ val stones = " aAAbbbb"
10+ numJewelsInStones(jewels, stones) shouldEqual 3
11+ }
12+
13+ it should " return 0 with jewels = 'c' and stones = 'aAAbbbb'" in {
14+ val jewels = " c"
15+ val stones = " aAAbbbb"
16+ numJewelsInStones(jewels, stones) shouldEqual 0
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments