Advertisement
MiroJoseph

Sum of two lowest positive integers

Apr 3rd, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.25 KB | None | 0 0
  1. My:
  2. object LowIntSum {
  3.  
  4.   def sumTwoSmallest(numbers: List[Int]): Int = {
  5.   val x=numbers.min
  6.   numbers.filterNot(n=>n==x).min+x}
  7. }
  8.  
  9. Other:
  10. object LowIntSum {
  11.  
  12.   def sumTwoSmallest(numbers: List[Int]): Int =
  13.     numbers.sorted.take(2).sum
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement