-
Notifications
You must be signed in to change notification settings - Fork 5
[java-onboarding-week-1] ivy.lee(이다예) 과제 제출합니다. #5
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
base: ivy/java-onboarding-week-1
Are you sure you want to change the base?
[java-onboarding-week-1] ivy.lee(이다예) 과제 제출합니다. #5
Conversation
msung99
left a comment
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.
고생하셨습니다 아이비!
| for (int i = 0; i < pleft.length(); i++){ | ||
| char ch = pleft.charAt(i); | ||
| lsum += Character.getNumericValue(ch); | ||
| } | ||
| int lmulti = 1; | ||
| for (int i = 0; i < pleft.length(); i++){ | ||
| char ch = pleft.charAt(i); | ||
| lmulti *= Character.getNumericValue(ch); | ||
| } | ||
|
|
||
| int rsum = 0; | ||
| for (int i = 0; i < pright.length(); i++){ | ||
| char ch = pright.charAt(i); | ||
| rsum += Character.getNumericValue(ch); | ||
| } | ||
|
|
||
| int rmulti = 1; | ||
| for (int i = 0; i < pright.length(); i++){ | ||
| char ch = pright.charAt(i); | ||
| rmulti *= Character.getNumericValue(ch); | ||
| } | ||
|
|
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.
공통 관심사 및 유사한 코드에 대해 메소드로 분리하면 가독성이 좋아지지 않을까요? 🤔
| if (pmaxValue > cmaxValue){ | ||
| answer = 1; | ||
| } else if (pmaxValue < cmaxValue) { | ||
| answer = 2; | ||
| } else { | ||
| answer = 0; | ||
| } | ||
|
|
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.
객체지향 프로그래밍 관점에서 else 문의 사용을 지양하라 라는 지향 원칙이 있습니다. 이에 관련한 내용 찾아보셔도 좋을 것 같습니다!
| for(int j = 0; j<list.size(); j++){ | ||
| for (int jj = 0; jj<friends.size(); jj++) { | ||
| List<String> target = friends.get(jj); | ||
| String target1 = target.get(0); | ||
| String target2 = target.get(1); | ||
|
|
||
| if (list.get(j).equals(target1)) { | ||
| if (map.containsKey(target2)) { | ||
| int tmpV = map.get(target2); | ||
| tmpV += 10; | ||
| map.put(target2, tmpV); | ||
| } else { | ||
| map.put(target2, 10); | ||
| } | ||
| } else if (list.get(j).equals(target2)) { | ||
| if (map.containsKey(target1)) { | ||
| int tmpV = map.get(target1); | ||
| tmpV += 10; | ||
| map.put(target1, tmpV); | ||
| } else { | ||
| map.put(target1, 10); | ||
| } | ||
| } | ||
| } |
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.
앞서 말씀 드렸던 내용과 동일한데, else 문을 지양하는게 좋습니다. else 문을 남용하면 자칫 중첩된 여러 조건문이 작성되고, 인덴트(들여쓰기)의 깊이가 늘어날 수 있기 때문입니다! if 절이 중첩되면서 동작흐름 파악이 힘든 Arrow Anti Pattern 이 전형적인 사례입니다.
https://haon.blog/haon/oop/principle-of-daily-gymnastics-front/
참고해보세요 ㅎㅎ
| for (int i = 0; i < cleft.length(); i++){ | ||
| char ch = cleft.charAt(i); | ||
| clsum += Character.getNumericValue(ch); | ||
| } | ||
| int clmulti = 1; | ||
| for (int i = 0; i < cleft.length(); i++){ | ||
| char ch = cleft.charAt(i); | ||
| clmulti *= Character.getNumericValue(ch); | ||
| } | ||
|
|
||
| int crsum = 0; | ||
| for (int i = 0; i < cright.length(); i++){ | ||
| char ch = cright.charAt(i); | ||
| crsum += Character.getNumericValue(ch); |
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.
전반적으로 모든 문제에서 for 문이 자주 사용되었는데, 가독성 개선을 위해 보통 stream API 기반 코드로 자주 대체하기도 합니다. 이와 관련하여 학습해보셔도 좋을 것 같습니다!
| Map<String, Integer> sortedMap = new LinkedHashMap<>(); | ||
| for (Map.Entry<String, Integer> entry : entryList) { | ||
| sortedMap.put(entry.getKey(), entry.getValue()); | ||
| } |
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.
HashMap 대신 LinkedHashMap 을 선택하신 이유가 있나요?? 사용시 어떠한 장단점이 있을까요?
alreadysons
left a comment
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.
고생하셨습니다!!
| public static int solution(List<Integer> pobi, List<Integer> crong) { | ||
| int answer = Integer.MAX_VALUE; | ||
|
|
||
| String pleft = String.valueOf(pobi.get(0)); |
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.
String 으로 하신 이유가 궁금합니다!
| public static String solution(String cryptogram) { | ||
| String answer = "answer"; | ||
| String tmp =""; | ||
| while (true) { |
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.
글자수로 반복문의 제한을 걸지않고 무한루프로 하신 이유가 궁금합니다!
| public static List<String> solution(String user, List<List<String>> friends, List<String> visitors) { | ||
| List<String> answer = Collections.emptyList(); | ||
|
|
||
| Map<String, Integer> map = new TreeMap<>(); |
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.
TreeMap에 대한 설명혹시 가능할까요??
No description provided.