Skip to content
This repository was archived by the owner on Sep 17, 2022. It is now read-only.

Commit dd1efab

Browse files
Add a solution for the April 15th challendge.
1 parent 7a17bc1 commit dd1efab

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Solution {
2+
fun productExceptSelf(nums: IntArray): IntArray {
3+
val left = IntArray(nums.size)
4+
val right = IntArray(nums.size)
5+
val result = IntArray(nums.size)
6+
7+
left[0] = 1
8+
for (i in 1 until nums.size) {
9+
left[i] = left[i - 1] * nums[i - 1]
10+
}
11+
12+
right[nums.size - 1] = 1
13+
for (i in nums.size - 2 downTo 0) {
14+
right[i] = right[i + 1] * nums[i + 1]
15+
}
16+
17+
for (i in nums.indices) {
18+
result[i] = left[i] * right[i]
19+
}
20+
21+
return result
22+
}
23+
}
24+
25+
fun main() {
26+
val solution = Solution()
27+
val result = solution.productExceptSelf(intArrayOf(2, 3, 4, 5))
28+
result.forEach { println(it) }
29+
}

30-days-leetcoding-challenge/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
| April 12 | [Last Stone Weight](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3297/) | [Solution.kt](https://github.com/alexey-agafonov/leetcode/tree/master/30-days-leetcoding-challenge/April%2012/src/Solution.kt) |
1717
| April 13 | [Contiguous Array](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3298/) | [Solution.kt](https://github.com/alexey-agafonov/leetcode/tree/master/30-days-leetcoding-challenge/April%2013/src/Solution.kt) |
1818
| April 14 | [Perform String Shifts](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3299/) | [Solution.kt](https://github.com/alexey-agafonov/leetcode/tree/master/30-days-leetcoding-challenge/April%2014/src/Solution.kt) |
19-
| April 15 | | |
19+
| April 15 | [Product of Array Except Self](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/530/week-3/3300/) | [Solution.kt](https://github.com/alexey-agafonov/leetcode/tree/master/30-days-leetcoding-challenge/April%2015/src/Solution.kt) |
2020
| April 16 | | |
2121
| April 17 | | |
2222
| April 18 | | |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Versions of used programming languages:
3333
| April 12 | [Last Stone Weight](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3297/) | [Solution.kt](https://github.com/alexey-agafonov/leetcode/tree/master/30-days-leetcoding-challenge/April%2012/src/Solution.kt) |
3434
| April 13 | [Contiguous Array](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3298/) | [Solution.kt](https://github.com/alexey-agafonov/leetcode/tree/master/30-days-leetcoding-challenge/April%2013/src/Solution.kt) |
3535
| April 14 | [Perform String Shifts](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/529/week-2/3299/) | [Solution.kt](https://github.com/alexey-agafonov/leetcode/tree/master/30-days-leetcoding-challenge/April%2014/src/Solution.kt) |
36-
| April 15 | | |
36+
| April 15 | [Product of Array Except Self](https://leetcode.com/explore/featured/card/30-day-leetcoding-challenge/530/week-3/3300/) | [Solution.kt](https://github.com/alexey-agafonov/leetcode/tree/master/30-days-leetcoding-challenge/April%2015/src/Solution.kt) |
3737
| April 16 | | |
3838
| April 17 | | |
3939
| April 18 | | |

0 commit comments

Comments
 (0)