Skip to content

solve: 8.String to Integer (atoi)#59

Open
t9a-dev wants to merge 1 commit intomainfrom
8.String-to-Integer-(atoi)
Open

solve: 8.String to Integer (atoi)#59
t9a-dev wants to merge 1 commit intomainfrom
8.String-to-Integer-(atoi)

Conversation

@t9a-dev
Copy link
Copy Markdown
Owner

@t9a-dev t9a-dev commented Mar 15, 2026

問題: 8. String to Integer (atoi)
次に解く問題: 6. Zigzag Conversion
ファイルの構成: ./src/bin/<各ステップ>.rs

Comment thread src/bin/step2a.rs
break;
};

if num > i32::MAX / 10 || num == i32::MAX / 10 && digit > i32::MAX % 10 {
Copy link
Copy Markdown

@huyfififi huyfififi Mar 15, 2026

Choose a reason for hiding this comment

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

代替案が提示できるわけではないのですが、positive に対しては単純に overflow をチェックしているように読める一方で、negative 側は-2147483648 を扱う関係で同じ意味では読めず、少し意図が分かりにくいように感じました。
ここの条件をoverflowチェックだと読み飛ばしてしまってから最後まで進んだ際、 positiveの場合 i32::MAXが最後まで許容されている一方で、negativeの場合 i32::MIN が early return される形になっており、挙動が対称でないので少し混乱しやすいように感じました。
(私の読解に問題があるような気もしますが😓)

Comment thread src/bin/step2a.rs
参考にした解法
https://github.com/hayashi-ay/leetcode/pull/69/changes#diff-f2b395d63173ac2f2d3c547e8f9e8e07c9acfbeb6b5da935bb28d83d8bcc7a04R145
https://github.com/Yoshiki-Iwasa/Arai60/pull/64/changes#diff-dbf5e75b50aa4257946026d6539860be248a58856e1b457b4d37445059b05857R21
if num > i32::MAX / 10 || num == i32::MAX / 10 && digit > i32::MAX % 10
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ここは自分で解いた時あまり深く理解できずに飛ばしてしまったところだったので、勉強になりました!

Comment thread src/bin/step2a.rs
break;
};

if num > i32::MAX / 10 || num == i32::MAX / 10 && digit > i32::MAX % 10 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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