Skip to content

Commit 05655f1

Browse files
committed
add tc, sc
1 parent 874fa17 commit 05655f1

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

β€Ž3sum/Geegong.javaβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
public class Geegong {
44

5+
/**
6+
* Time complexity : O(n^2)
7+
* space complexity : O(n^2)
8+
* @param nums
9+
* @return
10+
*/
511
public List<List<Integer>> threeSum(int[] nums) {
612

713
// μ€‘λ³΅λ˜λŠ” 값은 μ—†μ–΄μ•Ό ν•˜κΈ°μ— HashSet 으둜 result
814
HashSet<List<Integer>> result = new HashSet<>();
915

1016
// Key : λ°°μ—΄ μ›μ†Œ , value : List<String> μΈλ±μŠ€λ“€
1117
// elementMap 은 two pointer 의 값을 λ”ν•œ κ°’μ—μ„œ 0이 되기 μœ„ν•œ μš”μ†Œλ₯Ό μ°ΎκΈ°μœ„ν•΄ μ‚¬μš©λ  κ²ƒμž„
18+
// tc : O(n)
1219
Map<Integer, List<Integer>> elementMap = new HashMap<>();
1320
for (int index = 0; index<nums.length; index++) {
1421
int value = nums[index];
@@ -26,6 +33,7 @@ public List<List<Integer>> threeSum(int[] nums) {
2633
// leftIndex : 0μ—μ„œ λΆ€ν„° μ‹œμž‘ν•˜λŠ” index
2734
// rightIndex : nums.length - 1μ—μ„œλΆ€ν„° κ°μ†Œν•˜λŠ” index
2835
// leftIndex > rightIndex λ˜λŠ” μˆœκ°„κΉŒμ§€λ§Œ for문을 돌 것이닀.
36+
// tc : O(N^2 / 2)
2937
for (int leftIndex=0; leftIndex < nums.length; leftIndex++) {
3038
for (int rightIndex=nums.length - 1; rightIndex >= 0; rightIndex--) {
3139

@@ -71,3 +79,4 @@ public int findThirdIndexToBeZero(int leftIndex, int rightIndex, List<Integer> i
7179
return -1;
7280
}
7381
}
82+

0 commit comments

Comments
Β (0)