Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions to-lower-case/sonshn.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* 시간 복잡도: O(n)
* 공간 복잡도: O(n)
*/
class Solution {
public String toLowerCase(String s) {
StringBuilder sb = new StringBuilder();

for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);

if (c >= 'A' && c <= 'Z') {
c = (char) (c + 32);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

풀이 깔끔하게 잘 보았습니다 😊 혹시 참고가 될까 해서 남겨봅니다. c + 32 대신 비트 연산 c | 32로도 작성할 수 있더라고요. 대문자(65~90)는 32 비트가 꺼져 있어서 결과가 같다고 합니다.

c = (char) (c | 32);

가독성은 지금 방식이 더 좋아 보여서, 가볍게 참고만 해주세요!

}

sb.append(c);
}

return sb.toString();
}
}
Loading