File tree 2 files changed +21
-1
lines changed
product-of-array-except-self
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 1
1
class Solution {
2
- // ์๊ฐ : O(logN) , ๊ณต๊ฐ(2N)
2
+ // ์๊ฐ : O(NlogN)-์ ๋ ฌํ๋๋ฐ ๋๋ ์๊ฐ๋ณต์ก๋. , ๊ณต๊ฐ(2N)
3
3
fun twoSum (nums : IntArray , target : Int ): IntArray {
4
4
val sortNums = List (nums.size) { listOf (nums[it], it) }.sortedBy { it[0 ] }
5
5
// 1. list( list('๊ฐ', 'index')) ํํ์ list๋ฅผ ๋ง๋ค๊ณ ๊ฐ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํ๋ค.
You canโt perform that action at this time.
0 commit comments