Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions 2022/Oct/week_1/LeetCode_3Sum_손수연.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Oct_2022;

import java.util.*;

public class Solution_LeetCode_3Sum {

public List<List<Integer>> threeSum(int[] nums) {

Set<List<Integer>> set = new HashSet<>();

if(nums == null || nums.length < 3) return new ArrayList<>(set);

Arrays.sort(nums);

for (int i = 0; i < nums.length-2; i++) {
int j = i + 1;
int k = nums.length - 1;

while (j < k){
int sum = nums[i] + nums[j] + nums[k];

if(sum == 0) set.add(Arrays.asList(nums[i], nums[j++], nums[k--]));
else if(sum < 0) j++;
else if(sum > 0) k--;
}
}

return new ArrayList<>(set);
}
}
50 changes: 50 additions & 0 deletions 2022/Oct/week_1/프로그래머스_lv2_후보키_손수연.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package Oct_2022;

import java.util.*;

public class Solution_Programmers_42890_후보키 {

static ArrayList<HashSet<Integer>> candidate;

public int solution(String[][] relation){
candidate = new ArrayList<HashSet<Integer>>();
solve(0, new HashSet<Integer>(), relation);

return candidate.size();
}

static void solve(int n, HashSet<Integer> hashSet, String[][] relation){
if(n == relation[0].length) {
for(int i =0; i < candidate.size(); i++)
if(hashSet.containsAll(candidate.get(i))) return;

HashSet<String> set = new HashSet<>();

for(int r = 0; r < relation.length; r++){
String temp = "";

for(int c : hashSet) temp += relation[r][c] + ",";

if(set.contains(temp)) return;

set.add(temp);
}

candidate.add(hashSet);

return;
}

HashSet<Integer> set1 = new HashSet<>();
HashSet<Integer> set2 = new HashSet<>();

for(Integer value : hashSet){
set1.add(value);
set2.add(value);
}

solve(n+1, set2, relation);
set1.add(n);
solve(n+1, set1, relation);
}
}