Skip to content

Commit f68ea05

Browse files
committed
use scalafmt.
1 parent 4259728 commit f68ea05

File tree

192 files changed

+1517
-1375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+1517
-1375
lines changed

.scalafmt.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version = 3.9.3
2+
3+
maxColumn = 120
4+
rewrite.rules = [RedundantBraces, RedundantParens, SortImports]
5+
runner.dialect = scala213
6+
7+
continuationIndent {
8+
callSite = 2
9+
defnSite = 2
10+
extendSite = 2
11+
}

build.sbt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ organization := "com.counter2015"
44

55
version := "1.0"
66

7-
// same version to leetcode.com
87
scalaVersion := "2.13.16"
98

109

@@ -27,4 +26,7 @@ scalacOptions ++= Seq(
2726
-F - show full stack traces
2827
*/
2928
Test / testOptions += Tests.Argument("-oD")
30-
Global / onChangedBuildSource := ReloadOnSourceChanges
29+
Global / onChangedBuildSource := ReloadOnSourceChanges
30+
31+
scalafmtOnCompile := true
32+
semanticdbEnabled := true

project/plugins.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.1")
1+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.1")
2+
3+
//sbt-scalafmt https://github.com/scalameta/sbt-scalafmt
4+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4")

src/main/scala/algorithms/easy/basic/CountAndSay.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package algorithms.easy.basic
22

33
object CountAndSay {
44

5-
/** RunTime Info:
6-
* 268 ms, 48.6 MB
5+
/** RunTime Info: 268 ms, 48.6 MB
76
*
8-
* @param n the nth String of `CountAndSay`
9-
* @return the spell string
7+
* @param n
8+
* the nth String of `CountAndSay`
9+
* @return
10+
* the spell string
1011
*/
1112
def countAndSay(n: Int): String = {
1213

src/main/scala/algorithms/easy/basic/ExcelSheetColumnTitle.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ package algorithms.easy.basic
22

33
object ExcelSheetColumnTitle {
44

5-
/** Runtime Info:
6-
* 495 ms, 53.32 MB
5+
/** Runtime Info: 495 ms, 53.32 MB
76
*
87
* @param columnNumber
9-
* @return the 26 radix-string
8+
* @return
9+
* the 26 radix-string
1010
*/
1111
def convertToTitle(columnNumber: Int): String = {
1212
val radix = 26
1313

1414
@scala.annotation.tailrec
15-
def calcTitle(n: Int, res: String = ""): String = {
15+
def calcTitle(n: Int, res: String = ""): String =
1616
if (n > radix) {
1717
val r = n % radix
1818
if (r != 0) {
@@ -23,7 +23,6 @@ object ExcelSheetColumnTitle {
2323
} else {
2424
('A' + n - 1).toChar.toString + res
2525
}
26-
}
2726

2827
calcTitle(columnNumber)
2928
}

src/main/scala/algorithms/easy/basic/InsertionNode.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ import algorithms.struct.ListNode
44

55
object InsertionNode {
66

7-
/** RunTime Info:
8-
* 556 ms, 55.3 MB
7+
/** RunTime Info: 556 ms, 55.3 MB
98
*
10-
* @param headA head of list node A
11-
* @param headB head of list node B
12-
* @return the insertion node or null
9+
* @param headA
10+
* head of list node A
11+
* @param headB
12+
* head of list node B
13+
* @return
14+
* the insertion node or null
1315
*/
1416
def getIntersectionNode(headA: ListNode, headB: ListNode): ListNode = {
15-
def listLength(l: ListNode): Int = {
17+
def listLength(l: ListNode): Int =
1618
if (l == null) 0 else 1 + listLength(l.next)
17-
}
1819

1920
val (a, b) = (listLength(headA), listLength(headB))
2021
var (x, y) = (headA, headB)

src/main/scala/algorithms/easy/basic/LengthOfLastWord.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package algorithms.easy.basic
22

33
object LengthOfLastWord {
44

5-
/** RunTime Info:
6-
* 240 ms, 44.2 MB
5+
/** RunTime Info: 240 ms, 44.2 MB
76
*
8-
* @param s input string
9-
* @return length of last word
7+
* @param s
8+
* input string
9+
* @return
10+
* length of last word
1011
*/
11-
def lengthOfLastWord(s: String): Int = {
12+
def lengthOfLastWord(s: String): Int =
1213
if (s.filter(_ != ' ').length == 0) 0 else s.split(" ").last.length
13-
}
1414
}

src/main/scala/algorithms/easy/basic/ListCycle.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import algorithms.struct.ListNode
44

55
object ListCycle {
66

7-
/** RunTime Info:
8-
* 484 ms, 50.7 MB
7+
/** RunTime Info: 484 ms, 50.7 MB
98
*
10-
* @param head the head node of list
11-
* @return whether the list nodes have cycle
9+
* @param head
10+
* the head node of list
11+
* @return
12+
* whether the list nodes have cycle
1213
*/
13-
def hasCycle(head: ListNode): Boolean = {
14+
def hasCycle(head: ListNode): Boolean =
1415
if (head == null) false
1516
else {
1617
var fast = head
@@ -22,5 +23,4 @@ object ListCycle {
2223
}
2324
false
2425
}
25-
}
2626
}

src/main/scala/algorithms/easy/basic/LongestCommonPrefix.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ package algorithms.easy.basic
22

33
object LongestCommonPrefix {
44

5-
/** RunTime Info:
6-
* 244 ms, 44.8 MB
5+
/** RunTime Info: 244 ms, 44.8 MB
76
*
8-
* @param strs a string array
9-
* @return the longest common prefix string the input Array[string]
7+
* @param strs
8+
* a string array
9+
* @return
10+
* the longest common prefix string the input Array[string]
1011
*/
1112
def longestCommonPrefix(strs: Array[String]): String = {
1213
if (strs.length == 0) return ""
1314
val length = strs.map(_.length).min
1415
val num = strs.length
15-
for (l <- 0 until length; n <- 1 until num) {
16+
for (l <- 0 until length; n <- 1 until num)
1617
if (strs(n - 1)(l) != strs(n)(l)) return strs(0).slice(0, l)
17-
}
1818
strs(0).slice(0, length)
1919
}
2020
}

src/main/scala/algorithms/easy/basic/PalindromeNumber.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package algorithms.easy.basic
22

33
object PalindromeNumber {
44

5-
/** RunTime Info:
6-
* 292 ms, 46.7 MB
5+
/** RunTime Info: 292 ms, 46.7 MB
76
*
8-
* @param x input integer
9-
* @return check the integer is palindrome or not
7+
* @param x
8+
* input integer
9+
* @return
10+
* check the integer is palindrome or not
1011
*/
11-
def isPalindrome(x: Int): Boolean = {
12+
def isPalindrome(x: Int): Boolean =
1213
x.toString.reverse == x.toString
13-
}
1414
}

0 commit comments

Comments
 (0)