Open
Conversation
nodchip
reviewed
Apr 2, 2024
| - 数値を読んでいく | ||
|
|
||
| INT_MAX, INT_MINを超えたらそこで終了する。Pythonのintは理論上は上限がないので途中のオーバーフローなどは考えなくて良い。 | ||
| CやC++で実装する場合でも32bitより大きい型(long)を確保してあげれば考えなくて良くなる。← ただlongの場合のオーバーフローの考慮などどこかではちゃんと考慮しないといけない。その場合は、桁上りの計算をする前にオーバーフローするかどうかを判定すれば良い。 |
There was a problem hiding this comment.
long はデータモデルによってサイズが異なります。
https://ja.wikipedia.org/wiki/64%E3%83%93%E3%83%83%E3%83%88
LP64 LLP64 等でお調べください。
Owner
Author
There was a problem hiding this comment.
ありがとうございます。C++の規格では各typeの最小のbit数を規程していて、実際のサイズはその制約を満たす上で選択されたデータモデルによって決まるんですね。
C++の規格ではlongの最小サイズは32bitとして決められていて、LP32のようなデータモデルだと32bitになる。long long型については64bit以上であることが仕様上保証されている。
| index += 1 | ||
| return index | ||
|
|
||
| def get_sign(begin): |
There was a problem hiding this comment.
文字を解析してインデックスと符号を得ているため、 get より parse という単語を使用したほうがしっくりくると思います。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://leetcode.com/problems/string-to-integer-atoi