leetcode 4

LeetCode 841. Keys and Rooms (Java)

문제 링크 The problem link : LeetCode 841. Keys and Rooms 문제 요약 0번째부터 n-1까지 라벨이 붙여진 방이 있습니다. 0번째 문을 제외한 나머지 문은 잠겨있습니다. 방에 들어갔을때, 해당 방에 존재하는 key를 사용할 수 있게됩니다. 이렇게되면 key를 사용해 해당 방에 들어갈 수 있습니다. 당신의 목적은 0번째부터 n-1까지의 모든 방을 들어가는 겁니다. 가능할 경우 true를, 그렇지 않을 경우 false를 출력하세요. 예시 입력값 : rooms = [[1,3],[3,0,1],[2],[0]] 출력값 : false 해설 : 2번째 방(=[2])에 들어갈 수 없기 때문에 false입니다. 조건 - n == rooms.length - 2

LeetCode 1971. Find if Path Exists in Graph (Java)

문제 링크 The problem link : LeetCode 1971. Find if Path Exists in Graph 문제 요약 노드의 개수 n, 간선들이 연결되어있는지 알려주는 배열 edges, 출발지 source, 목적지 destination이 주어집니다. 해당 그래프에서 source와 destination이 연결되어있는지 확인하고, 연결되어있을 경우 true를 반환하세요. Input: n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2 Output: true Explanation: There are two paths from vertex 0 to vertex 2: - 0 → 1 → 2 - 0 → 2 문제 풀이 class Soluti..

LeetCode 771. Jewels and Stones (Java)

문제 링크 The problem link : Jewels and Stones - LeetCode 문제 요약 보석의 종류가 담겨진 String 타입의 변수, jewels가 있습니다. 돌의 종류 가 담겨진 String 타입의 변수 stones가 있습니다. 가지고 있는 돌의 종류 중, 총 몇개의 보석 종류가 있는지 확인하세요. 문제 풀이 class Solution { public int numJewelsInStones(String jewels, String stones) { String[] jTemp = jewels.split(""); String[] sTemp = stones.split(""); int ans = 0; for(int i=0; i