Skip to content

Commit 4627f1f

Browse files
committed
Update Text Justification to Swift4
1 parent f9a0077 commit 4627f1f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

String/TextJustification.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
class TextJustification {
9-
func fullJustify(words: [String], _ maxWidth: Int) -> [String] {
9+
func fullJustify(_ words: [String], _ maxWidth: Int) -> [String] {
1010
var res = [String]()
1111
var count = 0, last = 0
1212

@@ -15,7 +15,7 @@ class TextJustification {
1515
}
1616

1717
for i in 0..<words.count {
18-
let wordLen = words[i].characters.count
18+
let wordLen = words[i].count
1919

2020
if count + (i - last) + wordLen > maxWidth {
2121
var spaceNum = 0
@@ -40,7 +40,7 @@ class TextJustification {
4040
return res
4141
}
4242

43-
fileprivate func buildLine(words: [String], _ start: Int, _ end: Int, _ spaceNum: Int, _ extraNum: Int) -> String {
43+
fileprivate func buildLine(_ words: [String], _ start: Int, _ end: Int, _ spaceNum: Int, _ extraNum: Int) -> String {
4444
var res = ""
4545
var extraNum = extraNum
4646

@@ -60,7 +60,7 @@ class TextJustification {
6060
return res
6161
}
6262

63-
fileprivate func buildSpecialLine(words: [String], _ start: Int, _ end: Int, _ lineLength: Int) -> String {
63+
fileprivate func buildSpecialLine(_ words: [String], _ start: Int, _ end: Int, _ lineLength: Int) -> String {
6464
var res = ""
6565

6666
for i in start...end {
@@ -70,7 +70,7 @@ class TextJustification {
7070
}
7171
}
7272

73-
for _ in res.characters.count..<lineLength {
73+
for _ in res.count..<lineLength {
7474
res += " "
7575
}
7676

0 commit comments

Comments
 (0)