Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This function takes in a List, say {1,2,3,4,5}
- // It also takes in an int, say 2
- // the returning List[Int] should be filled with {1,1,2,2,3,3,4,4,5,5}
- def f(num:Int, arr:List[Int]):List[Int] = {
- var x : List[Int] = List()
- arr.foreach(data => x ::: addXTimes(data, num))
- def addXTimes(value:Int, time:Int):List[Int] = {
- var y : List[Int] = List()
- if(time > 0) {
- y ::: addXTimes(value, time-1)
- }
- y
- }
- x
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement