leetcode(3)
-
Floyd's Cycle Finding Algorithm (Find a loop in a linked list)
LeetCode의 141번을 풀다가 발견한 알고리즘. Linked List Cycle - LeetCode Linked List Cycle - Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internall leetcode.com 설명과 사진은 geeksforgeeks를 참고. Floyd’s Cycle Finding Algorithm - GeeksforGe..
2022.12.25 -
[LeetCode] 문제 복기(322번, 491번, 1372번, 1253번)
322. Coin Change 동전의 목록인 coins가 주어진다. coins로 만들어야하는 amount가 주어진다. coins로 amount를 만들때 가장 적은수를 사용하는 케이스를 출력해야한다. class Solution { public int coinChange(int[] coins, int amount) { // amount가 0이면 만들수 없다 if(amount == 0) return 0; int[] dp = new int[amount+1]; // dp 구현을 위한 공간 할당 Arrays.fill(dp, Integer.MAX_VALUE); // 각 dp 원소에는 Integer의 최대값으로 초기화 Arrays.sort(coins); // coins를 오름차순으로 sorting List coinLi..
2022.04.27 -
[LeetCode] 문제 복기(886번, 390번,684번,1685번,983번)
LeetCode를 풀면서 고생했던(?) 문제와 재밌게 풀었던 문제들을 돌아보는 시간. 886. Possible Bipartition 서로 함께할 수 없는 번호들이 주어지고 return으로 2개의 그룹을 만들 수 있는지를 넘겨줘야하는 문제다. 탐색으로 풀어야겠다고 생각하고 접근까지는 했으나 상태를 3개로 구분하지 못해서 헤맸다. (돌아보면 진짜 아무것도 아닌데) 방문, 미방문이 아니라 미방문, 그룹1, 그룹2 이런식으로 3가지의 상태를 통해 문제를 풀었어야했다. class Solution { public static boolean possibleBipartition(int N, int[][] dislikes) { int[] peopleGroup = new int[N+1]; Map graph = new Ha..
2022.04.17