Skip to content

Commit 50e39ef

Browse files
authored
Added tasks 858-870
1 parent eae9173 commit 50e39ef

File tree

14 files changed

+1040
-90
lines changed

14 files changed

+1040
-90
lines changed

README.md

Lines changed: 101 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
33
> ["For coding interview preparation, LeetCode is one of the best online resource providing a rich library of more than 300 real coding interview questions for you to practice from using one of the 7 supported languages - C, C++, Java, Python, C#, JavaScript, Ruby."](https://www.quora.com/How-effective-is-Leetcode-for-preparing-for-technical-interviews)
44
5-
* [Graph Theory I](#graph-theory-i)
65
* [SQL I](#sql-i)
76
* [Level 1](#level-1)
87
* [Level 2](#level-2)
@@ -16,93 +15,7 @@
1615
* [Dynamic Programming I](#dynamic-programming-i)
1716
* [Programming Skills I](#programming-skills-i)
1817
* [Programming Skills II](#programming-skills-ii)
19-
20-
### Graph Theory I
21-
22-
#### Day 1 Matrix Related Problems
23-
24-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
25-
|-|-|-|-|-|-
26-
| 0733 |[Flood Fill](src/main/kotlin/g0701_0800/s0733_flood_fill)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 230 | 97.76
27-
| 0200 |[Number of Islands](src/main/kotlin/g0101_0200/s0200_number_of_islands)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 252 | 95.41
28-
29-
#### Day 2 Matrix Related Problems
30-
31-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
32-
|-|-|-|-|-|-
33-
| 0695 |[Max Area of Island](src/main/kotlin/g0601_0700/s0695_max_area_of_island)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 324 | 24.06
34-
35-
#### Day 3 Matrix Related Problems
36-
37-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
38-
|-|-|-|-|-|-
39-
40-
#### Day 4 Matrix Related Problems
41-
42-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
43-
|-|-|-|-|-|-
44-
| 0417 |[Pacific Atlantic Water Flow](src/main/kotlin/g0401_0500/s0417_pacific_atlantic_water_flow)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 319 | 100.00
45-
46-
#### Day 5 Matrix Related Problems
47-
48-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
49-
|-|-|-|-|-|-
50-
| 0542 |[01 Matrix](src/main/kotlin/g0501_0600/s0542_01_matrix)| Medium | Array, Dynamic_Programming, Breadth_First_Search, Matrix | 441 | 94.06
51-
52-
#### Day 6 Matrix Related Problems
53-
54-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
55-
|-|-|-|-|-|-
56-
57-
#### Day 7 Standard Traversal
58-
59-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
60-
|-|-|-|-|-|-
61-
| 0797 |[All Paths From Source to Target](src/main/kotlin/g0701_0800/s0797_all_paths_from_source_to_target)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Backtracking | 232 | 100.00
62-
| 0841 |[Keys and Rooms](src/main/kotlin/g0801_0900/s0841_keys_and_rooms)| Medium | Depth_First_Search, Breadth_First_Search, Graph | 189 | 69.23
63-
64-
#### Day 8 Standard Traversal
65-
66-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
67-
|-|-|-|-|-|-
68-
| 0547 |[Number of Provinces](src/main/kotlin/g0501_0600/s0547_number_of_provinces)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 229 | 79.73
69-
70-
#### Day 9 Standard Traversal
71-
72-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
73-
|-|-|-|-|-|-
74-
| 0802 |[Find Eventual Safe States](src/main/kotlin/g0801_0900/s0802_find_eventual_safe_states)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 511 | 100.00
75-
76-
#### Day 10 Standard Traversal
77-
78-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
79-
|-|-|-|-|-|-
80-
| 0847 |[Shortest Path Visiting All Nodes](src/main/kotlin/g0801_0900/s0847_shortest_path_visiting_all_nodes)| Hard | Dynamic_Programming, Breadth_First_Search, Bit_Manipulation, Graph, Bitmask | 164 | 100.00
81-
82-
#### Day 11 Breadth First Search
83-
84-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
85-
|-|-|-|-|-|-
86-
| 0365 |[Water and Jug Problem](src/main/kotlin/g0301_0400/s0365_water_and_jug_problem)| Medium | Math, Depth_First_Search, Breadth_First_Search | 130 | 100.00
87-
88-
#### Day 12 Breadth First Search
89-
90-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
91-
|-|-|-|-|-|-
92-
| 0433 |[Minimum Genetic Mutation](src/main/kotlin/g0401_0500/s0433_minimum_genetic_mutation)| Medium | String, Hash_Table, Breadth_First_Search | 204 | 82.08
93-
| 0752 |[Open the Lock](src/main/kotlin/g0701_0800/s0752_open_the_lock)| Medium | Array, String, Hash_Table, Breadth_First_Search | 310 | 100.00
94-
| 0127 |[Word Ladder](src/main/kotlin/g0101_0200/s0127_word_ladder)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 396 | 98.68
95-
96-
#### Day 13 Graph Theory
97-
98-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
99-
|-|-|-|-|-|-
100-
101-
#### Day 14 Graph Theory
102-
103-
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
104-
|-|-|-|-|-|-
105-
| 0785 |[Is Graph Bipartite?](src/main/kotlin/g0701_0800/s0785_is_graph_bipartite)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 215 | 82.35
18+
* [Graph Theory I](#graph-theory-i)
10619

10720
### SQL I
10821

@@ -1658,6 +1571,7 @@
16581571

16591572
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
16601573
|-|-|-|-|-|-
1574+
| 0860 |[Lemonade Change](src/main/kotlin/g0801_0900/s0860_lemonade_change)| Easy | Array, Greedy | 413 | 86.96
16611575

16621576
#### Day 18
16631577

@@ -1680,13 +1594,112 @@
16801594
| 0622 |[Design Circular Queue](src/main/kotlin/g0601_0700/s0622_design_circular_queue)| Medium | Array, Design, Linked_List, Queue | 234 | 92.68
16811595
| 0729 |[My Calendar I](src/main/kotlin/g0701_0800/s0729_my_calendar_i)| Medium | Binary_Search, Design, Ordered_Set, Segment_Tree | 378 | 69.70
16821596

1597+
### Graph Theory I
1598+
1599+
#### Day 1 Matrix Related Problems
1600+
1601+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1602+
|-|-|-|-|-|-
1603+
| 0733 |[Flood Fill](src/main/kotlin/g0701_0800/s0733_flood_fill)| Easy | Array, Depth_First_Search, Breadth_First_Search, Matrix | 230 | 97.76
1604+
| 0200 |[Number of Islands](src/main/kotlin/g0101_0200/s0200_number_of_islands)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 252 | 95.41
1605+
1606+
#### Day 2 Matrix Related Problems
1607+
1608+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1609+
|-|-|-|-|-|-
1610+
| 0695 |[Max Area of Island](src/main/kotlin/g0601_0700/s0695_max_area_of_island)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find | 324 | 24.06
1611+
1612+
#### Day 3 Matrix Related Problems
1613+
1614+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1615+
|-|-|-|-|-|-
1616+
1617+
#### Day 4 Matrix Related Problems
1618+
1619+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1620+
|-|-|-|-|-|-
1621+
| 0417 |[Pacific Atlantic Water Flow](src/main/kotlin/g0401_0500/s0417_pacific_atlantic_water_flow)| Medium | Array, Depth_First_Search, Breadth_First_Search, Matrix | 319 | 100.00
1622+
1623+
#### Day 5 Matrix Related Problems
1624+
1625+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1626+
|-|-|-|-|-|-
1627+
| 0542 |[01 Matrix](src/main/kotlin/g0501_0600/s0542_01_matrix)| Medium | Array, Dynamic_Programming, Breadth_First_Search, Matrix | 441 | 94.06
1628+
1629+
#### Day 6 Matrix Related Problems
1630+
1631+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1632+
|-|-|-|-|-|-
1633+
1634+
#### Day 7 Standard Traversal
1635+
1636+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1637+
|-|-|-|-|-|-
1638+
| 0797 |[All Paths From Source to Target](src/main/kotlin/g0701_0800/s0797_all_paths_from_source_to_target)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Backtracking | 232 | 100.00
1639+
| 0841 |[Keys and Rooms](src/main/kotlin/g0801_0900/s0841_keys_and_rooms)| Medium | Depth_First_Search, Breadth_First_Search, Graph | 189 | 69.23
1640+
1641+
#### Day 8 Standard Traversal
1642+
1643+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1644+
|-|-|-|-|-|-
1645+
| 0547 |[Number of Provinces](src/main/kotlin/g0501_0600/s0547_number_of_provinces)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 229 | 79.73
1646+
1647+
#### Day 9 Standard Traversal
1648+
1649+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1650+
|-|-|-|-|-|-
1651+
| 0802 |[Find Eventual Safe States](src/main/kotlin/g0801_0900/s0802_find_eventual_safe_states)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort | 511 | 100.00
1652+
1653+
#### Day 10 Standard Traversal
1654+
1655+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1656+
|-|-|-|-|-|-
1657+
| 0847 |[Shortest Path Visiting All Nodes](src/main/kotlin/g0801_0900/s0847_shortest_path_visiting_all_nodes)| Hard | Dynamic_Programming, Breadth_First_Search, Bit_Manipulation, Graph, Bitmask | 164 | 100.00
1658+
1659+
#### Day 11 Breadth First Search
1660+
1661+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1662+
|-|-|-|-|-|-
1663+
| 0365 |[Water and Jug Problem](src/main/kotlin/g0301_0400/s0365_water_and_jug_problem)| Medium | Math, Depth_First_Search, Breadth_First_Search | 130 | 100.00
1664+
1665+
#### Day 12 Breadth First Search
1666+
1667+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1668+
|-|-|-|-|-|-
1669+
| 0433 |[Minimum Genetic Mutation](src/main/kotlin/g0401_0500/s0433_minimum_genetic_mutation)| Medium | String, Hash_Table, Breadth_First_Search | 204 | 82.08
1670+
| 0752 |[Open the Lock](src/main/kotlin/g0701_0800/s0752_open_the_lock)| Medium | Array, String, Hash_Table, Breadth_First_Search | 310 | 100.00
1671+
| 0127 |[Word Ladder](src/main/kotlin/g0101_0200/s0127_word_ladder)| Hard | Top_Interview_Questions, String, Hash_Table, Breadth_First_Search | 396 | 98.68
1672+
1673+
#### Day 13 Graph Theory
1674+
1675+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1676+
|-|-|-|-|-|-
1677+
1678+
#### Day 14 Graph Theory
1679+
1680+
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
1681+
|-|-|-|-|-|-
1682+
| 0785 |[Is Graph Bipartite?](src/main/kotlin/g0701_0800/s0785_is_graph_bipartite)| Medium | Depth_First_Search, Breadth_First_Search, Graph, Union_Find | 215 | 82.35
1683+
16831684
## Algorithms
16841685

16851686
| # | Title | Difficulty | Tag | Time, ms | Time, %
16861687
|------|----------------|-------------|-------------|----------|--------
16871688
| 1143 |[Longest Common Subsequence](src/main/kotlin/g1101_1200/s1143_longest_common_subsequence)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_17_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming | 307 | 38.36
16881689
| 0994 |[Rotting Oranges](src/main/kotlin/g0901_1000/s0994_rotting_oranges)| Medium | Array, Breadth_First_Search, Matrix, Algorithm_I_Day_9_Breadth_First_Search_Depth_First_Search, Level_2_Day_10_Graph/BFS/DFS | 308 | 57.93
1690+
| 0870 |[Advantage Shuffle](src/main/kotlin/g0801_0900/s0870_advantage_shuffle)| Medium | Array, Sorting, Greedy | 698 | 100.00
1691+
| 0869 |[Reordered Power of 2](src/main/kotlin/g0801_0900/s0869_reordered_power_of_2)| Medium | Math, Sorting, Counting, Enumeration | 145 | 87.50
1692+
| 0868 |[Binary Gap](src/main/kotlin/g0801_0900/s0868_binary_gap)| Easy | Bit_Manipulation | 142 | 100.00
1693+
| 0867 |[Transpose Matrix](src/main/kotlin/g0801_0900/s0867_transpose_matrix)| Easy | Array, Matrix, Simulation | 201 | 100.00
1694+
| 0866 |[Prime Palindrome](src/main/kotlin/g0801_0900/s0866_prime_palindrome)| Medium | Math | 143 | 100.00
1695+
| 0865 |[Smallest Subtree with all the Deepest Nodes](src/main/kotlin/g0801_0900/s0865_smallest_subtree_with_all_the_deepest_nodes)| Medium | Hash_Table, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 147 | 100.00
16891696
| 0864 |[Shortest Path to Get All Keys](src/main/kotlin/g0801_0900/s0864_shortest_path_to_get_all_keys)| Hard | Breadth_First_Search, Bit_Manipulation | 176 | 100.00
1697+
| 0863 |[All Nodes Distance K in Binary Tree](src/main/kotlin/g0801_0900/s0863_all_nodes_distance_k_in_binary_tree)| Medium | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 147 | 95.83
1698+
| 0862 |[Shortest Subarray with Sum at Least K](src/main/kotlin/g0801_0900/s0862_shortest_subarray_with_sum_at_least_k)| Hard | Array, Binary_Search, Heap_Priority_Queue, Prefix_Sum, Sliding_Window, Queue, Monotonic_Queue | 563 | 84.62
1699+
| 0861 |[Score After Flipping Matrix](src/main/kotlin/g0801_0900/s0861_score_after_flipping_matrix)| Medium | Array, Greedy, Matrix, Bit_Manipulation | 135 | 71.43
1700+
| 0860 |[Lemonade Change](src/main/kotlin/g0801_0900/s0860_lemonade_change)| Easy | Array, Greedy, Programming_Skills_II_Day_17 | 413 | 86.96
1701+
| 0859 |[Buddy Strings](src/main/kotlin/g0801_0900/s0859_buddy_strings)| Easy | String, Hash_Table | 149 | 91.01
1702+
| 0858 |[Mirror Reflection](src/main/kotlin/g0801_0900/s0858_mirror_reflection)| Medium | Math, Geometry | 120 | 100.00
16901703
| 0857 |[Minimum Cost to Hire K Workers](src/main/kotlin/g0801_0900/s0857_minimum_cost_to_hire_k_workers)| Hard | Array, Sorting, Greedy, Heap_Priority_Queue | 302 | 100.00
16911704
| 0856 |[Score of Parentheses](src/main/kotlin/g0801_0900/s0856_score_of_parentheses)| Medium | String, Stack | 129 | 84.62
16921705
| 0855 |[Exam Room](src/main/kotlin/g0801_0900/s0855_exam_room)| Medium | Design, Ordered_Set | 644 | 83.33

src/main/kotlin/g0601_0700/s0695_max_area_of_island/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ Return _the maximum **area** of an island in_ `grid`. If there is no island, ret
3939
```kotlin
4040
@Suppress("NAME_SHADOWING")
4141
class Solution {
42-
fun maxAreaOfIsland(grid: Array<IntArray>?): Int {
43-
if (grid.isNullOrEmpty()) {
42+
fun maxAreaOfIsland(grid: Array<IntArray>): Int {
43+
if (grid.isEmpty()) {
4444
return 0
4545
}
4646
val m = grid.size
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 858\. Mirror Reflection
5+
6+
Medium
7+
8+
There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered `0`, `1`, and `2`.
9+
10+
The square room has walls of length `p` and a laser ray from the southwest corner first meets the east wall at a distance `q` from the <code>0<sup>th</sup></code> receptor.
11+
12+
Given the two integers `p` and `q`, return _the number of the receptor that the ray meets first_.
13+
14+
The test cases are guaranteed so that the ray will meet a receptor eventually.
15+
16+
**Example 1:**
17+
18+
![](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/06/18/reflection.png)
19+
20+
**Input:** p = 2, q = 1
21+
22+
**Output:** 2
23+
24+
**Explanation:** The ray meets receptor 2 the first time it gets reflected back to the left wall.
25+
26+
**Example 2:**
27+
28+
**Input:** p = 3, q = 1
29+
30+
**Output:** 1
31+
32+
**Constraints:**
33+
34+
* `1 <= q <= p <= 1000`
35+
36+
## Solution
37+
38+
```kotlin
39+
@Suppress("NAME_SHADOWING")
40+
class Solution {
41+
fun mirrorReflection(p: Int, q: Int): Int {
42+
var p = p
43+
var q = q
44+
while (p % 2 == 0 && q % 2 == 0) {
45+
p /= 2
46+
q /= 2
47+
}
48+
return if (p % 2 == 0) {
49+
2
50+
} else if (q % 2 == 0) {
51+
0
52+
} else {
53+
1
54+
}
55+
}
56+
}
57+
```
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
[![](https://img.shields.io/github/stars/javadev/LeetCode-in-Kotlin?label=Stars&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin)
2+
[![](https://img.shields.io/github/forks/javadev/LeetCode-in-Kotlin?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/javadev/LeetCode-in-Kotlin/fork)
3+
4+
## 859\. Buddy Strings
5+
6+
Easy
7+
8+
Given two strings `s` and `goal`, return `true` _if you can swap two letters in_ `s` _so the result is equal to_ `goal`_, otherwise, return_ `false`_._
9+
10+
Swapping letters is defined as taking two indices `i` and `j` (0-indexed) such that `i != j` and swapping the characters at `s[i]` and `s[j]`.
11+
12+
* For example, swapping at indices `0` and `2` in `"abcd"` results in `"cbad"`.
13+
14+
**Example 1:**
15+
16+
**Input:** s = "ab", goal = "ba"
17+
18+
**Output:** true
19+
20+
**Explanation:** You can swap s[0] = 'a' and s[1] = 'b' to get "ba", which is equal to goal.
21+
22+
**Example 2:**
23+
24+
**Input:** s = "ab", goal = "ab"
25+
26+
**Output:** false
27+
28+
**Explanation:** The only letters you can swap are s[0] = 'a' and s[1] = 'b', which results in "ba" != goal.
29+
30+
**Example 3:**
31+
32+
**Input:** s = "aa", goal = "aa"
33+
34+
**Output:** true
35+
36+
**Explanation:** You can swap s[0] = 'a' and s[1] = 'a' to get "aa", which is equal to goal.
37+
38+
**Constraints:**
39+
40+
* <code>1 <= s.length, goal.length <= 2 * 10<sup>4</sup></code>
41+
* `s` and `goal` consist of lowercase letters.
42+
43+
## Solution
44+
45+
```kotlin
46+
class Solution {
47+
fun buddyStrings(s: String, goal: String): Boolean {
48+
var first = -1
49+
val second: Int
50+
val sCounts = IntArray(26)
51+
if (s == goal) {
52+
for (i in s.indices) {
53+
sCounts[s[i].code - 'a'.code]++
54+
if (sCounts[s[i].code - 'a'.code] > 1) {
55+
return true
56+
}
57+
}
58+
}
59+
for (i in s.indices) {
60+
val curr = s[i]
61+
sCounts[curr.code - 'a'.code]++
62+
if (curr != goal[i]) {
63+
if (first == -1) {
64+
first = i
65+
} else {
66+
second = i
67+
val ss = s.toCharArray()
68+
val temp = ss[first]
69+
ss[first] = ss[second]
70+
ss[second] = temp
71+
return String(ss) == goal
72+
}
73+
}
74+
}
75+
return false
76+
}
77+
}
78+
```

0 commit comments

Comments
 (0)