-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8-kjs254 #30
8-kjs254 #30
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ¦ μ½ν μμ IDE νμ©μ μν΄μ£Όλκ³³λ μλ€κ³ λ€μ΄μ νλ‘κ·Έλλ¨Έμ€ λ¬Έμ λ IDEμμ΄ κ°λ°ν΄λ³΄κ³€ νλλ° μ΄ λ¬Έμ λ μμ² μ΄λ ΅λ€μ.... (javaλΌμ λ μ΄λ €μ λκ²λ μμ΅λλ€.)
μ λμ λ리(맡)λ₯Ό μ λ ¬ν μκ°μ λͺ»νκ³ λ°λ‘ ν΄λμ€λ₯Ό νλ λ§λ€μ΄μ 리μ€νΈμλ€ μ§μ΄λκ³ μ λ ¬λ°©λ²μ λλ€λ‘ μ λ¬ν΄μ£Όλ λ°©λ²μΌλ‘ ꡬννμ΅λλ€.
μλλ μ κ° ν΄κ²°ν μ½λμΈλ° μ’μ μ½λλ μλλΌ ν΄μνμ§ λ§μκ³ μ΄λ κ² λλ½κ² νΌ λλ μꡬλ~ μ λλ‘ λ΄μ£Όμλ©΄ λ κ² κ°μ΅λλ€.
import java.util.ArrayList;
import java.util.Comparator;
public class P_νν {
}
class Solution {
public int[] solution(String s) {
s = s.substring(1, s.length() - 1);
boolean bracket = false;
Nodes nodes = new Nodes();
int number = 0;
for (int i = 0; i < s.length(); i++) {
char now = s.charAt(i);
if (now == '{') {
bracket = true;
continue;
} else if (now == '}') {
bracket = false;
continue;
}
if (bracket) {
if (now != ',') {
number *= 10;
number += Character.getNumericValue(now);
} else {
Node node = nodes.getNode(number);
if (node == null) nodes.putNode(number);
else node.plusCount();
}
}
}
nodes.sort();
int[] answer = new int[nodes.nodeList.size()];
for (int i = 0; i < answer.length; i++) {
answer[i] = nodes.nodeList.get(i).id;
}
return answer;
}
}
class Nodes {
ArrayList<Node> nodeList = new ArrayList<>();
public Node getNode(int id) {
for (Node node : nodeList) {
if (node.id == id) {
return node;
}
}
return null;
}
public void putNode(int id) {
this.nodeList.add(new Node(id));
}
public void sort() {
nodeList.sort(new Comparator<>() {
@Override
public int compare(Node o1, Node o2) {
return o1.count - o2.count;
}
});
}
}
class Node {
int id;
int count = 1;
public void plusCount() {
this.count++;
}
public Node(int id) {
this.id = id;
}
}
λκ° μμ² κΈΈμ£ ? νν³.. λ°€μ΄λΌμ λ¨Έλ¦¬κ° μ μλμκ°λλ€.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν΄λ²μ κ½€ κ°λ¨νμ§λ§, κ°μΈμ μΌλ‘ μ μΆλ ₯ ꡬν μͺ½μμ μκ°λ³΄λ€ κΉλ€λ‘μ΄ λ¬Έμ μΈ κ² κ°μ΅λλ€. μ½λλ§ λ³΄λ©΄ μ λ§ κ°λ¨ν΄ 보μ΄λ€μ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ€ν λ¬Έμμ΄ μ²λ¦¬μ μμ΄μ Pythonμ΄ λκ² μ’μκ±° κ°κΈ΄ ν©λλ€!!
λ¬Όλ‘ λ€λ₯Έ μΈμ΄μμλ μ¬μ©ν μ μκ² μ§λ§ μ λ κ°μΈμ μΌλ‘ Pythonμ΄ λκ² μ§κ΄μ μ΄λΌκ³ μκ°μ νλλ°, μ΄λ₯Ό λͺ
ννκ² λ³΄μ¬μ£Όλ μ½λμΈ κ² κ°μ΅λλ€.
λμ
λ리λ₯Ό μ΄μ©νλ μ’μ νμ΄μλκ±° κ°μ΅λλ€.
μκ³ νμ
¨μ΅λλ€.π
π λ¬Έμ λ§ν¬
νν
βοΈ μμλ μκ°
1h
β¨ μλ μ½λ
1. λ¬Έμ ν΄μ
μλ₯Ό λ€μ΄ ννμ΄
(2, 1, 3, 4)
μΈ κ²½μ°λ n-ννμ΄ λ€μκ³Ό κ°μ΄ μμ μ μμ΅λλ€.κ·Έλ₯ 보면 ννμ μ¬λΌμ΄μ±ν λ¨μν μ§ν©μ΄μ§λ§ μ΄ λ μ§ν©μ μμλ μμκ° λ°λμ΄λ μκ΄μμΌλ λ€μκ³Ό κ°μ΄ λ€λ₯΄κ² ννν μ μμ΅λλ€.
λ°λΌμ κ° μ§ν©μ κ°μμ μμλ₯Ό μ μ λ ¬νλ κ²μ΄ μ΄ λ¬Έμ μ κ΄κ±΄
μΈμ€ μμμΌλ ν΄λ΅μ κ°κΉμ΄μ μμμ΅λλ€.
κ²°κ³Όμ μΌλ‘ κ° μμ λΉλμλ₯Ό λ΄λ¦Όμ°¨μμΌλ‘ μ λ ¬νλ©΄ λ°λ‘ λ΅μ μΆλ ₯ ν μ μλ λ¬Έμ μ λλ€.
μ΄μ©μ§ μ λ ₯μ΄ λͺ¨λ λ¬Έμμ΄λ‘ μ£Όμ΄μ Έ μμ΄ μ΄λ»κ² μμ λ μ§ λκ°νμ΅λλ€..
λ°λΌμ λ€μκ³Ό κ°μ΄ μλμ½λλ₯Ό μμ±ν©λλ€.
2. μλμ½λ
μ 체 μ½λ
λμ λ리λ₯Ό
key
κ°μ κΈ°μ€μΌλ‘ μ λ ¬νλλ° μ΄λ €μμ΄ μμ΄ μ‘°κΈ μμ보λ νμ΄μ¬ λμ λ리 μ λ ¬μμ μμΈν μ€λͺ μ΄ λμ΄ μμ΄ λ¨κ²¨λ΄ λλ€.π μλ‘κ² μκ²λ λ΄μ©
λμ λ리 μ λ ¬μ λν΄μ ꡬ체μ μΌλ‘ μ΄ν΄ν μ μλ κΈ°νμμ΅λλ€.
λν λ±μ λ°μ΄ μ΄λ‘λ€λκ±Έ μ λλ‘ μ κ² λμμ΅λλ€.
μμ¦ PRμ΄ μκΎΈ λ¦μ΄μ§κ³ μμ΄ μ£μ‘ν©λλ€..
λ€λ₯Έ μΌλ€μ΄ λ§μ μκ° μ¬μ κ° λ무 λΆμ‘±νμ§λ§ 건μ±μΌλ‘ PRμ μμ±νκ³ μΆμ§ μμ μκΎΈλ§ λ―Έλ£¨κ² λμμ΅λλ€. ν루λΌλ 빨리 λ°λΌμ‘λλ‘ νκ² μ΅λλ€. κ°μ¬ν©λλ€.