1. 초기화 1) 초기화를 안하는 경우 : (보통)adj[i][i]는 0, adj[i][j]는 INF로 초기화를 해주어야함. 다만, 사이클을 체크할 경우에는 adj[i][i]도 INF로 초기화해주어야함. 2) 초기화를 잘못하는 경우 : 정점이 0이 아닌 1부터 들어오는데, for (int i = 0; i < V; ++i) adj[i][i] = 0; 이렇게 초기화 하지 말것.... 2. 입력 그래프의 입력부분에서 u에서 v로 가는 간선이 가중치가 다른채로 여러개 존재하는 경우가 있다. (1, 2, 5), (1, 2, 10) 이 경우 입력순이 아닌 작은것을 택하도록 해야한다. adj[u][v] = min(adj[u][v], w);
문자열의 용량을 나타내 주는 strlen() 함수의 헤더 파일은 , 이다. 이 함수는 매개변수로 string을 입력받는다. 이때, strlen()은 문자열의 용량을 문자열의 끝을 찾는 방법을 통해 알아낸다. 즉, 문자열의 첫 character부터 시작하여 문자열의 끝을 알리는 \n을 찾을 때까지 문자열의 용량만큼을 탐색하는 것이다. 따라서 이것이 반복문, 대표적으로 1중 for문과 함께 쓰인다면 그 시간 복잡도는 O(n^2)이 될 것이다. 다음은 O(n^2) 코드이다. #include char a[100000]; int main(){ // O(n^2) for(int i=0; i
JAVA 풀이 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class _10825 { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stk; int N = Integer.parseInt(br.read..
Java 8을 기준으로 Arrays.sort() 는 primitive arrays에 대해 Dual-Pivot Quicksort 을 수행하며, Object type arrays에 대해 Merge Sort 보다 향상된 Tim Sort 를 수행함. Collections.sort()는 내부적으로 Arrays.sort()를 수행할뿐이다. 결론 일반적인 배열은 Arrays.sort() 사용 List는 Collections.sort() 사용
문제 https://leetcode.com/problems/single-number/ Given a non-empty array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?Example 1:Input: [2,2,1] Output: 1 Example 2:Input: [4,1,2,1,2] Output: 4----------------------------------------------------------------..
문제 https://leetcode.com/problems/jewels-and-stones/ You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a"..
- Total
- Today
- Yesterday
- BOJ
- 정렬
- 코딩
- collections
- sort
- 자바
- 실수
- quicksort
- 10825
- C++
- 용량
- MergeSort
- leetcode
- strlen
- 플로이드
- 국영수
- length
- tim sort
- java
- String
- 개발
- str.length()
- 길이
- Arrays.sort
- 알고리즘
- Collections.sort
- Arrays
- Comparator
- 문자열
- 시간복잡도
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |