-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat: add kotlin solutions to lc problems #3492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c5caac7
feat: add kotlin solution to lc problem: No.0001
Zuoqiu-Yingyi 0b032a2
feat: add kotlin solution to lc problem: No.0034
Zuoqiu-Yingyi 9ec2933
feat: add kotlin solution to lc problem: No.1870
Zuoqiu-Yingyi 394c28d
feat: add solutions to lc problem: No.1898
Zuoqiu-Yingyi 1638bd6
feat: add solutions to lc problem: No.0912
Zuoqiu-Yingyi 384d59a
feat: add kotlin solution to lc problem: No.0415
Zuoqiu-Yingyi 22aa558
feat: add kotlin solution to lc problem: No.0043
Zuoqiu-Yingyi abc99d4
feat: add kotlin solution to lc problem: No.0303
Zuoqiu-Yingyi 5074e18
feat: add kotlin solution to lc problem: No.0304
Zuoqiu-Yingyi b97c6d3
feat: add kotlin solution to lc problem: No.2132
Zuoqiu-Yingyi a5c969d
feat: add kotlin solution to lc problem: No.0003
Zuoqiu-Yingyi 4192b92
feat: add kotlin solution to lc problem: No.0713
Zuoqiu-Yingyi 6651f77
feat: add solutions to lc problem: No.0191
Zuoqiu-Yingyi 143d9a3
feat: add solutions to lc problem: No.0056
Zuoqiu-Yingyi 68e192c
Merge branch 'main' into feat/solutions
Zuoqiu-Yingyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
solution/0000-0099/0001.Two Sum/Solution.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class Solution { | ||
fun twoSum(nums: IntArray, target: Int): IntArray { | ||
val m = mutableMapOf<Int, Int>() | ||
nums.forEachIndexed { i, x -> | ||
val y = target - x | ||
val j = m.get(y) | ||
if (j != null) { | ||
return intArrayOf(j, i) | ||
} | ||
m[x] = i | ||
} | ||
return intArrayOf() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class Solution { | ||
fun lengthOfLongestSubstring(s: String): Int { | ||
var char_set = BooleanArray(128) | ||
var left = 0 | ||
var ans = 0 | ||
s.forEachIndexed { right, c -> | ||
while (char_set[c.code]) { | ||
char_set[s[left].code] = false | ||
left++ | ||
} | ||
char_set[c.code] = true | ||
ans = Math.max(ans, right - left + 1) | ||
} | ||
return ans | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
solution/0000-0099/0034.Find First and Last Position of Element in Sorted Array/Solution.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Solution { | ||
fun searchRange(nums: IntArray, target: Int): IntArray { | ||
val left = this.search(nums, target) | ||
val right = this.search(nums, target + 1) | ||
return if (left == right) intArrayOf(-1, -1) else intArrayOf(left, right - 1) | ||
} | ||
|
||
private fun search(nums: IntArray, target: Int): Int { | ||
var left = 0 | ||
var right = nums.size | ||
while (left < right) { | ||
val middle = (left + right) / 2 | ||
if (nums[middle] < target) { | ||
left = middle + 1 | ||
} else { | ||
right = middle | ||
} | ||
} | ||
return left | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.