Skip to content

Commit

Permalink
Updated spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
javadev authored Nov 19, 2024
1 parent 505c02e commit 8878878
Show file tree
Hide file tree
Showing 1,739 changed files with 6,742 additions and 5,410 deletions.
13 changes: 9 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
kotlin("jvm") version "2.0.21"
jacoco
id("org.sonarqube") version "5.1.0.4882"
id("com.diffplug.spotless") version "6.12.0"
id("com.diffplug.spotless") version "6.21.0"
`maven-publish`
}

Expand Down Expand Up @@ -52,9 +52,14 @@ spotless {
kotlin {
encoding("UTF-8")
target("**/src/**/*.kt")
ktlint("0.43.0").userData(mapOf(
"max_line_length" to "120"
))
ktlint("0.50.0").editorConfigOverride(
mapOf(
"max_line_length" to "120",
"indent_size" to "4",
"ktlint_standard_package-name" to "disabled",
"ktlint_standard_comment-wrapping" to "disabled"
)
)
toggleOffOn()
trimTrailingWhitespace()
endWithNewline()
Expand Down
2 changes: 1 addition & 1 deletion pom-central.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>1.9.20</version>
<version>2.0.0-Beta</version>
<executions>
<execution>
<phase>prepare-package</phase>
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com_github_leetcode/Employee.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class Employee(
/** the importance value of this employee */
var importance: Int,
/** the id of direct subordinates */
var subordinates: List<Int> = listOf()
var subordinates: List<Int> = listOf(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ class Solution {
var lpsCenter = 0
var lpsRadius = 0
for (i in newStr.indices) {
dp[i] = if (friendCenter + friendRadius > i) Math.min(
dp[friendCenter * 2 - i],
friendCenter + friendRadius - i
) else 1
dp[i] = if (friendCenter + friendRadius > i) {
Math.min(
dp[friendCenter * 2 - i],
friendCenter + friendRadius - i,
)
} else {
1
}
while (i + dp[i] < newStr.size && i - dp[i] >= 0 && newStr[i + dp[i]] == newStr[i - dp[i]]) {
dp[i]++
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Solution {
i,
j - 2,
s,
p
p,
)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Solution {
nums: String,
letters: Array<String>,
curr: StringBuilder,
ans: MutableList<String>
ans: MutableList<String>,
) {
if (curr.length == nums.length) {
ans.add(curr.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class Solution {
fun mergeKLists(lists: Array<ListNode>): ListNode? {
return if (lists.isEmpty()) {
null
} else mergeKLists(lists, 0, lists.size)
} else {
mergeKLists(lists, 0, lists.size)
}
}

private fun mergeKLists(lists: Array<ListNode>, leftIndex: Int, rightIndex: Int): ListNode? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Solution {
// move a word's length each time
var j = i
while (j + window <= s.length) {

// get the subStr
val subStr = s.substring(j, j + window)
val map: MutableMap<String, Int> = HashMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Solution {
target: Int,
start: Int,
sums: MutableList<List<Int>>,
sum: LinkedList<Int>
sum: LinkedList<Int>,
) {
if (target == 0) {
// make a deep copy of the current combination
Expand All @@ -28,7 +28,6 @@ class Solution {
}
var i = start
while (i < candidates.size && target >= candidates[i]) {

// If candidate[i] equals candidate[i-1], then solutions for i is subset of
// solution of i-1
if (i == start || i > start && candidates[i] != candidates[i - 1]) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/g0001_0100/s0046_permutations/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Solution {
nums: IntArray,
finalResult: MutableList<List<Int>>,
currResult: MutableList<Int>,
used: BooleanArray
used: BooleanArray,
) {
if (currResult.size == nums.size) {
finalResult.add(ArrayList(currResult))
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/g0001_0100/s0048_rotate_image/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Solution {
intArrayOf(i, j),
intArrayOf(j, n - 1 - i),
intArrayOf(n - 1 - i, n - 1 - j),
intArrayOf(n - 1 - j, i)
intArrayOf(n - 1 - j, i),
)
var t = matrix[pos[0][0]][pos[0][1]]
for (k in 1 until pos.size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Solution {
ch.sort()
val temp = String(ch)
hm.computeIfAbsent(
temp
temp,
) { _: String? -> ArrayList() }
hm.getValue(temp).add(s)
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/g0001_0100/s0050_powx_n/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Solution {
}
return if (n < 0) {
1.0 / res
} else res
} else {
res
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/g0001_0100/s0052_n_queens_ii/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Solution {
row: BooleanArray,
col: BooleanArray,
diagonal: BooleanArray,
antiDiagonal: BooleanArray
antiDiagonal: BooleanArray,
): Int {
if (r == n) {
return 1
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/g0001_0100/s0079_word_search/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Solution {
word: String,
index: Int,
x: Int,
y: Int
y: Int,
): Boolean {
if (index == word.length) {
return true
Expand Down Expand Up @@ -40,7 +40,7 @@ class Solution {
fun exist(board: Array<CharArray>, word: String): Boolean {
val visited = Array(board.size) {
BooleanArray(
board[0].size
board[0].size,
)
}
for (i in board.indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Solution {
maxOfThreeNums(
largestArea(a, start, minInd),
a[minInd] * (limit - start),
largestArea(a, minInd + 1, limit)
largestArea(a, minInd + 1, limit),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Solution {
'.' +
octets[2] +
'.' +
octets[3]
octets[3],
)
} else if (count < 4 && pos < 12) {
var octet = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Solution {
i1: Int,
i2: Int,
i3: Int,
cache: Array<Array<Boolean?>>
cache: Array<Array<Boolean?>>,
): Boolean {
if (cache[i1][i2] != null) {
return cache[i1][i2]!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Solution {
}
return if (root.`val` <= left || root.`val` >= right) {
false
} else solve(root.left, left, root.`val`.toLong()) && solve(root.right, root.`val`.toLong(), right)
} else {
solve(root.left, left, root.`val`.toLong()) && solve(root.right, root.`val`.toLong(), right)
}
}
}
4 changes: 3 additions & 1 deletion src/main/kotlin/g0001_0100/s0100_same_tree/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class Solution {
return if (n != null && m != null) {
if (n.`val` != m.`val`) {
false
} else trav(n.left, m.left) && trav(n.right, m.right)
} else {
trav(n.left, m.left) && trav(n.right, m.right)
}
} else {
n == null && m == null
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/kotlin/g0101_0200/s0101_symmetric_tree/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class Solution {
fun isSymmetric(root: TreeNode?): Boolean {
return if (root == null) {
true
} else helper(root.left, root.right)
} else {
helper(root.left, root.right)
}
}

private fun helper(leftNode: TreeNode?, rightNode: TreeNode?): Boolean {
Expand All @@ -29,6 +31,8 @@ class Solution {
}
return if (leftNode.`val` != rightNode.`val`) {
false
} else helper(leftNode.left, rightNode.right) && helper(leftNode.right, rightNode.left)
} else {
helper(leftNode.left, rightNode.right) && helper(leftNode.right, rightNode.left)
}
}
}
4 changes: 3 additions & 1 deletion src/main/kotlin/g0101_0200/s0112_path_sum/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Solution {
}
return if (targetSum == root.`val` && root.left == null && root.right == null) {
true
} else hasPathSum(root.left, targetSum - root.`val`) || hasPathSum(root.right, targetSum - root.`val`)
} else {
hasPathSum(root.left, targetSum - root.`val`) || hasPathSum(root.right, targetSum - root.`val`)
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/g0101_0200/s0113_path_sum_ii/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Solution {
al: ArrayList<Int>,
sum: Int,
targetSum: Int,
root: TreeNode?
root: TreeNode?,
) {
var sum = sum
if (root == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/g0101_0200/s0120_triangle/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Solution {
triangle[row][col] +
Math.min(
dfs(triangle, dp, row + 1, col),
dfs(triangle, dp, row + 1, col + 1)
dfs(triangle, dp, row + 1, col + 1),
)
)
dp[row][col] = sum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package g0101_0200.s0123_best_time_to_buy_and_sell_stock_iii
class Solution {
fun maxProfit(prices: IntArray): Int {
val n = prices.size
if (n <2) {
if (n < 2) {
return 0
}
val a = IntArray(n) { 0 }
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/g0101_0200/s0126_word_ladder_ii/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Solution {
if (isLadder(word, next)) {
// construct the reverse graph from endWord
val reverseLadders = reverse.computeIfAbsent(
next
next,
) { _: String? -> HashSet() }
reverseLadders.add(word)
if (endWord == next) {
Expand Down Expand Up @@ -71,7 +71,7 @@ class Solution {
beginWord: String,
graph: Map<String, MutableSet<String>>,
ans: MutableList<List<String>>,
path: MutableSet<String>
path: MutableSet<String>,
) {
val next = graph[endWord] ?: return
for (word in next) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Solution {
if (num == lastNum) {
continue
}
length ++
length++
if (num - lastNum > 1) {
length = 1
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/g0101_0200/s0134_gas_station/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Solution {
}
return if (sumGas < sumCost) {
-1
} else result
} else {
result
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/g0101_0200/s0140_word_break_ii/Solution.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Solution {
wordSet: Set<String>,
index: Int,
sb: StringBuilder,
result: MutableList<String>
result: MutableList<String>,
) {
if (index == s.length) {
if (sb[sb.length - 1] == ' ') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Solution {
"/" to { a, b -> a / b },
"*" to { a, b -> a * b },
"+" to { a, b -> a + b },
"-" to { a, b -> a - b }
"-" to { a, b -> a - b },
)
fun evalRPN(tokens: Array<String>): Int {
val stack = ArrayDeque<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ class Solution {
fun findMin(nums: IntArray): Int {
return if (nums.isEmpty()) {
0
} else find(0, nums.size - 1, nums)
} else {
find(0, nums.size - 1, nums)
}
}

private fun find(left: Int, right: Int, nums: IntArray): Int {
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/g0101_0200/s0155_min_stack/MinStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ class MinStack() {
private val stack: ArrayDeque<Pair<Int, Int>> = ArrayDeque()

fun push(x: Int) {
val min: Int = if (stack.isEmpty()) x
else getMin()
val min: Int = if (stack.isEmpty()) {
x
} else {
getMin()
}
stack.addLast(x to minOf(min, x))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Solution {
-0x10,
-0x8,
-0x4,
-0x2
-0x2,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Solution {
private fun buildGraph(
numCourses: Int,
prerequisites: Array<IntArray>,
indegrees: IntArray
indegrees: IntArray,
): List<List<Int>> {
val graph = List(numCourses) { mutableListOf<Int>() }
for ((cur, prev) in prerequisites) {
Expand Down
Loading

0 comments on commit 8878878

Please sign in to comment.