Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Pull changes from main repo #2

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 133 commits into from
May 30, 2020
Merged
Changes from 2 commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
3333a7b
Add java solution2 for day16: Odd Even Linked List
qilingit May 17, 2020
2dc80ea
Merge pull request #100 from supaggregator/master
jinshendan May 17, 2020
b5d5583
Merge pull request #101 from qilingit/day16
jinshendan May 17, 2020
68c8c2a
add cpp solution
jinshendan May 17, 2020
da83902
update doc
jinshendan May 17, 2020
2476a5e
update doc
jinshendan May 17, 2020
7f7fdfe
Add Solution python
WANGZijian1994 May 17, 2020
bc56889
Add java solution for Day17 Find All Anagrams In a String
yfeng1 May 17, 2020
fbec145
Merge pull request #102 from yang-feng-yfeng/master
jinshendan May 17, 2020
086bcf4
add kotlin solution for 438 Find-All-Anagrams-In-A-String.kt
MagicienDeCode May 17, 2020
44514a8
Merge pull request #103 from MagicienDeCode/master
jinshendan May 17, 2020
87e3eee
Add java solution2 for day16: Find All Anagrams in a String
qilingit May 17, 2020
c4794d9
Merge pull request #104 from qilingit/day17
jinshendan May 17, 2020
8cfc915
Add java sliding window solution
qilingit May 17, 2020
0648bda
Merge pull request #105 from qilingit/day17
jinshendan May 17, 2020
5e801b5
add scala solutions for questions 15,16,17
HangMerlin May 17, 2020
f8f49aa
Merge pull request #106 from HangMerlin/master
jinshendan May 17, 2020
eda0944
[May 18, 2020] Add cpp solution2
kerms May 17, 2020
2c85f8d
Merge pull request #107 from kerms/patch-1
jinshendan May 17, 2020
603c109
update doc
jinshendan May 18, 2020
a2b15fc
add scala solution for Permutation-In-String
HangMerlin May 18, 2020
ea68692
update doc
jinshendan May 18, 2020
37c8aac
rename file
jinshendan May 18, 2020
fafaa3c
Merge pull request #108 from HangMerlin/master
jinshendan May 18, 2020
6e0c55a
Add Solution in Python
WANGZijian1994 May 18, 2020
aec4966
Add Solution Python
WANGZijian1994 May 18, 2020
0701afc
add kotlin solution for 567 Permutation-In-String.kt
MagicienDeCode May 18, 2020
d2ce2e3
Merge pull request #109 from MagicienDeCode/master
jinshendan May 18, 2020
2eba7a2
[May 18, 2020] Add cpp sulution2
kerms May 18, 2020
29641c8
Merge pull request #110 from kerms/patch-2
jinshendan May 18, 2020
a063c5c
Add Java solution for day18: Permutation in String
qilingit May 18, 2020
3bc529c
Merge pull request #111 from qilingit/day18
jinshendan May 18, 2020
aa9316a
add cpp solution
jinshendan May 19, 2020
108745a
update doc
jinshendan May 19, 2020
cc5ea30
add cpp solution 2
jinshendan May 19, 2020
e7612d7
Add java solution for Day19 Online Stock Span
yfeng1 May 19, 2020
69ef92c
Merge pull request #112 from yang-feng-yfeng/master
jinshendan May 19, 2020
c02e2b8
add kotlin solution for 901 Online-Stock-Span.kt
MagicienDeCode May 19, 2020
e4f3505
Merge pull request #113 from MagicienDeCode/master
jinshendan May 19, 2020
9162f4f
add scala solutions for Online-Stock-Span
HangMerlin May 19, 2020
d092ec1
Merge pull request #114 from HangMerlin/master
jinshendan May 19, 2020
75db4ec
add cpp solution
jinshendan May 20, 2020
7d9d543
update doc
jinshendan May 20, 2020
c93b345
add kotlin solution for 230 Kth-Smallest-Element-In-A-BST.kt
MagicienDeCode May 20, 2020
e40435e
Merge pull request #115 from MagicienDeCode/master
jinshendan May 20, 2020
902b9a4
Add Java solution1 for day20: Kth Smallest Element in a BST
qilingit May 20, 2020
50e3d3d
Merge pull request #116 from qilingit/day20
jinshendan May 20, 2020
b681b31
Improve Java solution1 into inorder-traversal for day20: Kth Smallest…
qilingit May 20, 2020
83879df
Merge pull request #117 from qilingit/day20
jinshendan May 21, 2020
171652b
Add Kth smallest
mincong-h May 21, 2020
8c02dff
Add README
mincong-h May 21, 2020
6c12139
Merge pull request #118 from mincong-h/java
jinshendan May 21, 2020
cae6814
add cp solution
jinshendan May 21, 2020
51982bd
update doc
jinshendan May 21, 2020
b1b29d2
add kotlin solution for 1277 Count-Square-Submatrices-With-All-Ones.kt
MagicienDeCode May 21, 2020
abe1d91
Merge pull request #119 from MagicienDeCode/master
jinshendan May 21, 2020
86a145a
Add java solution for day 21 count square submatrices with all ones
yfeng1 May 21, 2020
eb5b6ce
Merge pull request #120 from yang-feng-yfeng/master
jinshendan May 21, 2020
1fddd55
add cpp solution 2
jinshendan May 21, 2020
c913961
Merge branch 'master' of https://github.com/jinshendan/Leetcode
jinshendan May 21, 2020
b11f9f8
Add Java solution2 dynamic programming for day21: Count Square Submat…
qilingit May 21, 2020
ff47501
Add Java solution2 dynamic programming for day21: Count Square Submat…
qilingit May 21, 2020
b655faf
Merge pull request #121 from qilingit/day21
jinshendan May 21, 2020
2f884d1
add cpp solution
jinshendan May 22, 2020
bbd0fb4
update doc
jinshendan May 22, 2020
1bda191
add kotlin solution for 451 Sort-Characters-By-Frequency.kt
MagicienDeCode May 22, 2020
5356089
Merge pull request #122 from MagicienDeCode/master
jinshendan May 22, 2020
45451a6
A simple Java version
QianHx May 22, 2020
557b7e0
Merge pull request #123 from QianHx/master
jinshendan May 22, 2020
6b24aa4
Correcting indentation
jingwen-z May 22, 2020
4f6daed
Formatting
jingwen-z May 22, 2020
50e465a
Add python solution
jingwen-z May 22, 2020
4647d0a
Remove useless character
jingwen-z May 22, 2020
ecd3c70
Merge pull request #124 from jingwen-z/python-solution
jinshendan May 22, 2020
3238497
add cpp solution
jinshendan May 23, 2020
6cf1e3c
update doc
jinshendan May 23, 2020
557aaaf
add kotlin solution for 986 Interval-List-Intersections.kt
MagicienDeCode May 23, 2020
114de14
Merge pull request #125 from MagicienDeCode/master
jinshendan May 23, 2020
35a4b0c
add scala solutions for 20 - 23
HangMerlin May 23, 2020
b809810
Merge pull request #126 from HangMerlin/master
jinshendan May 23, 2020
d21642f
Add Java solution for day23: Interval List Intersections
qilingit May 23, 2020
e19acfd
Merge pull request #128 from qilingit/day23
jinshendan May 24, 2020
928a0db
add cpp solution
jinshendan May 24, 2020
1144eb0
update doc
jinshendan May 24, 2020
c342746
add kotlin solution for 1008 Construct-Binary-Search-Tree-From-Preord…
MagicienDeCode May 24, 2020
0b097d3
Merge pull request #129 from MagicienDeCode/master
jinshendan May 24, 2020
593f081
Q20: update scala solutions ,Q24: add scala solutions
HangMerlin May 24, 2020
368b00e
Merge pull request #130 from HangMerlin/master
jinshendan May 24, 2020
fa6139b
Add Java solution for day24: Construct Binary Search Tree from Preord…
qilingit May 24, 2020
b188974
Add Java solution for day24: Construct Binary Search Tree from Preord…
qilingit May 24, 2020
5f38168
Merge pull request #131 from qilingit/day24
jinshendan May 24, 2020
540dee7
[24 May, 2020] add cpp solution2
kerms May 24, 2020
6efe174
Merge pull request #132 from kerms/patch-3
jinshendan May 24, 2020
4cd5105
Add python solution
jingwen-z May 25, 2020
eeb1c4d
Merge pull request #133 from jingwen-z/python-solution
jinshendan May 25, 2020
3f4eaa5
add cpp solution
jinshendan May 25, 2020
fdda4a3
update doc
jinshendan May 25, 2020
5ad6133
add kotlin solution for 1035 Uncrossed-Lines.kt
MagicienDeCode May 25, 2020
c56301c
Merge pull request #134 from MagicienDeCode/master
jinshendan May 25, 2020
a72df79
Add Java solution for day25: Uncrossed Lines
qilingit May 25, 2020
a5d4ff2
Merge pull request #135 from qilingit/day25
jinshendan May 26, 2020
bdc14ae
add cpp solution
jinshendan May 26, 2020
a53bb81
update doc
jinshendan May 26, 2020
7936cb2
add kotlin solution for 525 Contiguous-Array.kt
MagicienDeCode May 26, 2020
89c6ae7
Merge pull request #136 from MagicienDeCode/master
jinshendan May 26, 2020
94aa849
Add Java solution for day 26: Contiguous Array
qilingit May 26, 2020
db1d98c
Merge pull request #137 from qilingit/day26
jinshendan May 27, 2020
c3a2dd8
add cpp solution
jinshendan May 27, 2020
0407054
update doc
jinshendan May 27, 2020
574f279
improve cpp
jinshendan May 27, 2020
5b056a2
improve cpp
jinshendan May 27, 2020
7682238
add kotlin solution for 886 Possible-Bipartition.kt
MagicienDeCode May 27, 2020
025813b
Add Java solution for day27: Possible Bipartition
qilingit May 27, 2020
f14996b
Merge pull request #138 from MagicienDeCode/master
jinshendan May 28, 2020
8807eca
Merge pull request #139 from qilingit/day27
jinshendan May 28, 2020
a083084
add cpp solution
jinshendan May 28, 2020
c7bc6e7
update doc
jinshendan May 28, 2020
b59836c
add kotlin solution for 338 Counting-Bits.kt
MagicienDeCode May 28, 2020
54570ec
[28 May, 2020] Add cpp solution2 and solution3
kerms May 28, 2020
18a83ef
Merge pull request #140 from MagicienDeCode/master
jinshendan May 28, 2020
17328a3
Merge pull request #141 from kerms/patch-4
jinshendan May 28, 2020
80fd3c6
Add Java solution for day28: Counting Bits
qilingit May 29, 2020
08dda97
Merge pull request #142 from qilingit/day28
jinshendan May 29, 2020
11907cc
add cpp solution
jinshendan May 29, 2020
4cd56a0
update doc
jinshendan May 29, 2020
20c7e00
add kotlin solution for 207 Course-Schedule.kt
MagicienDeCode May 29, 2020
a47ce29
Merge pull request #143 from MagicienDeCode/master
jinshendan May 29, 2020
68f056c
Add Java solution for day29: Course Schedule
qilingit May 29, 2020
7e889f7
Merge pull request #144 from qilingit/day29
jinshendan May 30, 2020
f7f14a0
add cpp solution
jinshendan May 30, 2020
b7adf99
update doc
jinshendan May 30, 2020
14f3bef
add kotlin solution for 973 K-Closest-Points-To-Origin.kt
MagicienDeCode May 30, 2020
31c9988
Merge pull request #145 from MagicienDeCode/master
jinshendan May 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions 43 May-LeetCoding-Challenge/28-Counting-Bits/Counting-Bits.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class CountingBitsKotlin338 {
/*
0 -> 0
1 -> 1

2 -> 1
3 -> 2

4 -> 1
5 -> 2
6 -> 2
7 -> 3
*/
fun countBits(num: Int): IntArray {
val result = IntArray(num + 1)
for (index in result.indices) {
result[index] = result[index.shr(1)] + if (index % 2 == 0) 0 else 1
}
return result
}

/*
fun countBits(num: Int): IntArray {
return IntRange(0, num).map(this::bitCountOne).toIntArray()
}

private fun bitCountOne(target: Int): Int {
var count = 0
var n = target
while (n != 0) {
count += n % 2
n /= 2
}
return count
}
*/
}

fun main() {
val solution = CountingBitsKotlin338()
// 0 1 1 2 1 2
solution.countBits(5).forEach(::print)
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.