Skip to content

Commit b1a3b4b

Browse files
committed
[Week3](gmlwls96) Product of array except self
1 parent 26b6991 commit b1a3b4b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
// ์‹œ๊ฐ„ : O(2n) = O(n) ,๊ณต๊ฐ„ : O(1)
3+
fun productExceptSelf(nums: IntArray): IntArray {
4+
val answer = IntArray(nums.size) { 1 }
5+
6+
var n = 1
7+
for (i in 0 until nums.lastIndex) {
8+
n *= nums[i]
9+
answer[i + 1] = n
10+
}
11+
println(answer.toList())
12+
13+
n = 1
14+
for (i in nums.lastIndex downTo 1) {
15+
n *= nums[i]
16+
answer[i - 1] *= n
17+
}
18+
return answer
19+
}
20+
}

โ€Žtwo-sum/gmlwls96.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Solution {
2-
// ์‹œ๊ฐ„ : O(logN), ๊ณต๊ฐ„(2N)
2+
// ์‹œ๊ฐ„ : O(NlogN)-์ •๋ ฌํ•˜๋Š”๋ฐ ๋“œ๋Š” ์‹œ๊ฐ„๋ณต์žก๋„., ๊ณต๊ฐ„(2N)
33
fun twoSum(nums: IntArray, target: Int): IntArray {
44
val sortNums = List(nums.size) { listOf(nums[it], it) }.sortedBy { it[0] }
55
// 1. list( list('๊ฐ’', 'index')) ํ˜•ํƒœ์˜ list๋ฅผ ๋งŒ๋“ค๊ณ  ๊ฐ’์„ ๊ธฐ์ค€์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.

0 commit comments

Comments
ย (0)