Recent Posts
간단명료
Pair 본문
C/C++의 구조체처럼 JAVA에서도 변수들의 집합을 사용하여 Pair(짝)처럼 활용하여 알고리즘 풀 때 도움이 된다.
C의 구조체 활용
struct str{
int x,y;
}
int main void(){
vector<str> v;
v.push_bach({1,2});
cout << v[0].x << ' ' << v[0].y;
}
/*결과
1 2
*/
java의 클래스활용
class pair{
int x,y;
pair(int x,int y){
this.x = x;
this.y = y;
}
}
class Solution {
public int[] solution() {
Queue<pair> q = new LinkedList<>();
for(int i=0;i<1;i++) {
q.add(new pair(1,2));
int x = q.peek().x;
int y = q.peek().y;
System.out.println(x+" "+y);
q.add(new pair(x,y));
}
}
}
/*결과
1 2
*/
관련문제
https://programmers.co.kr/learn/courses/30/lessons/42586?language=java
풀이
https://github.com/chogyujin/algorithm/blob/1b1a5043b72d69aeab52143a76beec8ae29827a6/programmers/004.%20%EA%B8%B0%EB%8A%A5%EA%B0%9C%EB%B0%9C.md
728x90
반응형
'Java' 카테고리의 다른 글
Queue (0) | 2022.02.16 |
---|---|
List - Array 데이터 이동 (0) | 2022.02.16 |
ArrayList (0) | 2022.02.16 |
Math 클래스 (0) | 2022.02.16 |
length, length(), size() (0) | 2022.02.16 |