Skip to content

Conversation

@pq5910
Copy link
Contributor

@pq5910 pq5910 commented May 16, 2024

240516 김우정 0x02 풀이

int n = scanner.nextInt();
scanner.close();

StringBuilder output = new StringBuilder();
Copy link
Collaborator

@Taeyong98 Taeyong98 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringBuilder 라는 객체를 처음 봤는데
이게 append 메소드가 String객체의 += 연산자보다 엄청 빠르다고 하더라고요!
저도 이제 이거로 알고리즘 풀어야 할듯 하네요

StringBuilder line = new StringBuilder();

for (int row = 0; row < 2 * n - 1; row++) {
line.setLength(0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저같은 경우는 for 문이 시작할 때마다 String 객체를 생성 했는데 우정님은 line.setLength(0)을 함으로써 기존 객체를 재사용하는 게 시간적으로 더 효과적이겠네요. 하나 더 배웠습니다. 감사합니다!


return new Pair(max, index+1);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 클래스를 사용하여 푸신 이유가 따로 있으실까요?
이점이 따로 있다면 알려주시면 감사하겠습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그러게요.. 그냥 아무 생각없이 자연스럽게 함수로 해야겠다는 생각을 했었는데 아마도 배열과 관련된 함수가 최댓값을 찾는 함수, 최솟값을 찾는 함수 등 여러가지가 구현될 수 있으니까 당연하게 다른 기능들과 추가되기 쉽게 당연하게 함수들로 만들어야겠다..라고 생각했던 것 같아요! 지금 문제에서는 다른 분들 코드를 확인했더니 그냥 main에서 하는게 가독성도 좋고 깔끔하겠더라구요!

@lee-JunR lee-JunR merged commit 08f2675 into lee-JunR:main May 17, 2024
@pq5910 pq5910 deleted the KWJ branch May 20, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants