@@ -11,10 +11,8 @@ object WordShift {
11
11
*/
12
12
def shift (words : List [String ], pos : Int , target : Int ) : List [String ] = {
13
13
val (l, r) = words.splitAt(pos)
14
- if (l.mkString(" " ).length < (target - 5 )) {
15
- return shiftRight(l, r, target)
16
- }
17
- return shiftLeft(l, r, target)
14
+ if (l.mkString(" " ).length < (target - 5 )) shiftRight(l, r, target)
15
+ else shiftLeft(l, r, target)
18
16
}
19
17
20
18
/*
@@ -23,16 +21,12 @@ object WordShift {
23
21
*of the first list is "smaller enough" than the target parameter.
24
22
*/
25
23
private def shiftRight (l : List [String ], r : List [String ], target : Int ) : List [String ] = {
26
- if (r.length == 0 ) {
27
- return l
28
- }
24
+ if (r.length == 0 ) return l
29
25
30
26
val (r1, r2) = r.splitAt(r.length- 1 )
31
27
val l1 = r2 ++ l
32
28
33
- if (l1.mkString(" " ).length > (target - 5 )) {
34
- return l ++ r
35
- }
29
+ if (l1.mkString(" " ).length > (target - 5 )) return l ++ r
36
30
37
31
return shiftRight(l1, r1, target)
38
32
}
@@ -43,16 +37,12 @@ object WordShift {
43
37
*of the first list is "smaller enough" than the target parameter.
44
38
*/
45
39
private def shiftLeft (l : List [String ], r : List [String ], target : Int ) : List [String ]= {
46
- if (l.length == 0 ) {
47
- return r
48
- }
40
+ if (l.length == 0 ) return r
49
41
50
42
val (l1, l2) = l.splitAt(1 )
51
43
val r1 = r ++ l1
52
44
53
- if (l2.mkString(" " ).length < (target - 5 )) {
54
- return l2 ++ r1
55
- }
45
+ if (l2.mkString(" " ).length < (target - 5 )) return l2 ++ r1
56
46
57
47
return shiftLeft(l2, r1, target)
58
48
}
0 commit comments