Skip to content

Create 387.md#15

Open
hiroki-horiguchi-dev wants to merge 1 commit into
mainfrom
hashmap-387
Open

Create 387.md#15
hiroki-horiguchi-dev wants to merge 1 commit into
mainfrom
hashmap-387

Conversation

@hiroki-horiguchi-dev
Copy link
Copy Markdown
Owner

387. First Unique Character in a Stringを解きました、レビューをお願いします

@hiroki-horiguchi-dev hiroki-horiguchi-dev self-assigned this May 10, 2026
Comment thread hashmap/387.md
}

for (int i = 0; i < s.length(); i++) {
if (frequency.get(s.charAt(i)).equals(1)) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

if (frequency.get(s.charAt(i)) == 1) {

と書いても、アンボクシングされるため、意図通り動くようです。

https://docs.oracle.com/javase/specs/jls/se17/html/jls-15.html#jls-15.21.1

If the operands of an equality operator are both of numeric type, or one is of numeric type and the other is convertible (§5.1.8) to numeric type, binary numeric promotion is performed on the operands (§5.6).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

コメントありがとうございます!
等号演算子を使ったとき、片方がプリミティブであり、もう片方がアンボクシング可能ならアンボクシングされてから演算されるのですね。
Cluadeは Integer == Integer の比較になると言っていましたが、危うく嘘を信じ込むところでした。。
一次情報をもっと読み込むべきでした。

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.

2 participants