8000 the sum of two integer may overflow. see · nationcall/leetcode@fb62b95 · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"commit":{"oid":"fb62b9578ae645188db52bcb52d72ff356367060","url":"/nationcall/leetcode/commit/fb62b9578ae645188db52bcb52d72ff356367060","authoredDate":"2014-11-19T17:25:10.000+08:00","committedDate":"2014-11-19T17:25:10.000+08:00","shortMessage":null,"shortMessageMarkdown":"\u003cdiv\u003ethe sum of two integer may overflow. see\u003c/div\u003e","shortMessageMarkdownLink":null,"bodyMessageHtml":"\u003ca href=\"http://googleresearch.blogspot.jp/2006/06/extra-extra-read-all-about-it-nearly.html\" rel=\"nofollow\"\u003ehttp://googleresearch.blogspot.jp/2006/06/extra-extra-read-all-about-it-nearly.html\u003c/a\u003e\nfor details.","authors":[{"login":"advancedxy","displayName":"Ye Xianjin","avatarUrl":"https://avatars.githubusercontent.com/u/807537?v=4","path":"/advancedxy","isGitHub":false}],"committerAttribution":false,"committer":{"login":"advancedxy","displayName":"Ye Xianjin","avatarUrl":"https://avatars.githubusercontent.com/u/807537?v=4","path":"/advancedxy","isGitHub":false},"parents":["f3a597e0e565676db4f771e4d841cdb0ed192ab6"],"globalRelayId":"MDY6Q29tbWl0NDg4NDM2NTY6ZmI2MmI5NTc4YWU2NDUxODhkYjUyYmNiNTJkNzJmZjM1NjM2NzA2MA==","sha1":"f3a597e0e565676db4f771e4d841cdb0ed192ab6","sha2":"fb62b9578ae645188db52bcb52d72ff356367060"},"currentUser":null,"repo":{"id":48843656,"defaultBranch":"master","name":"leetcode","ownerLogin":"nationcall","currentUserCanPush":false,"isFork":true,"isEmpty":false,"createdAt":"2015-12-31T09:21:28.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/13973202?v=4","public":true,"private":false,"isOrgOwned":false},"diffEntryData":[{"diffLines":[{"stylingDirective":null,"type":"HUNK","blobLineNumber":181,"text":"@@ -182,7 +182,7 @@ \\subsubsection{代码}","html":"@@ -182,7 +182,7 @@ \\subsubsection{代码}","displayNoNewLineWarning":false,"position":0,"left":181,"right":181},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":182,"text":" int search(int A[], int n, int target) {","html":" int search(int A[], int n, int target) {","displayNoNewLineWarning":false,"position":1,"left":182,"right":182},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":183,"text":" int first = 0, last = n;","html":" int first = 0, last = n;","displayNoNewLineWarning":false,"position":2,"left":183,"right":183},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":184,"text":" while (first != last) {","html":" while (first != last) {","displayNoNewLineWarning":false,"position":3,"left":184,"right":184},{"stylingDirective":null,"type":"DELETION","blobLineNumber":185,"text":"- const int mid = (first + last) / 2;","html":"- const int mid = \u003cspan class=\"x x-first x-last\"\u003e(\u003c/span\u003efirst \u003cspan class=\"x x-first x-last\"\u003e+ \u003c/span\u003elast) / 2;","displayNoNewLineWarning":false,"position":4,"left":185,"right":184},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":185,"text":"+ const int mid = first + (last - first) / 2;","html":"+ const int mid = first \u003cspan class=\"x x-first x-last\"\u003e + (\u003c/span\u003elast\u003cspan class=\"x x-first x-last\"\u003e - first\u003c/span\u003e) / 2;","displayNoNewLineWarning":false,"position":5,"left":185,"right":185},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":186,"text":" if (A[mid] == target)","html":" if (A[mid] == target)","displayNoNewLineWarning":false,"position":6,"left":186,"right":186},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":187,"text":" return mid;","html":" return mid;","displayNoNewLineWarning":false,"position":7,"left":187,"right":187},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":188,"text":" if (A[first] \u003c= A[mid]) {","html":" if (A[first] \u0026lt;= A[mid]) {","displayNoNewLineWarning":false,"position":8,"left":188,"right":188},{"stylingDirective":null,"type":"HUNK","blobLineNumber":239,"text":"@@ -240,7 +240,7 @@ \\subsubsection{代码}","html":"@@ -240,7 +240,7 @@ \\subsubsection{代码}","displayNoNewLineWarning":false,"position":9,"left":239,"right":239},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":240,"text":" bool search(int A[], int n, int target) {","html":" bool search(int A[], int n, int target) {","displayNoNewLineWarning":false,"position":10,"left":240,"right":240},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":241,"text":" int first = 0, last = n;","html":" int first = 0, last = n;","displayNoNewLineWarning":false,"position":11,"left":241,"right":241},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":242,"text":" while (first != last) {","html":" while (first != last) {","displayNoNewLineWarning":false,"position":12,"left":242,"right":242},{"stylingDirective":null,"type":"DELETION","blobLineNumber":243,"text":"- const int mid = (first + last) / 2;","html":"- const int mid = \u003cspan class=\"x x-first x-last\"\u003e(\u003c/span\u003efirst \u003cspan class=\"x x-first x-last\"\u003e+ \u003c/span\u003elast) / 2;","displayNoNewLineWarning":false,"position":13,"left":243,"right":242},{"stylingDirective":null,"type":"ADDITION","blobLineNumber":243,"text":"+ const int mid = first + (last - first) / 2;","html":"+ const int mid = first \u003cspan class=\"x x-first x-last\"\u003e + (\u003c/span\u003elast\u003cspan class=\"x x-first x-last\"\u003e - first\u003c/span\u003e) / 2;","displayNoNewLineWarning":false,"position":14,"left":243,"right":243},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":244,"text":" if (A[mid] == target)","html":" if (A[mid] == target)","displayNoNewLineWarning":false,"position":15,"left":244,"right":244},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":245,"text":" return true;","html":" return true;","displayNoNewLineWarning":false,"position":16,"left":245,"right":245},{"stylingDirective":null,"type":"CONTEXT","blobLineNumber":246,"text":" if (A[first] \u003c A[mid]) {","html":" if (A[first] \u0026lt; A[mid]) {","displayNoNewLineWarning":false,"position":17,"left":246,"right":246}],"diffNumber":0,"diffSize":"0 Bytes","isBinary":false,"isTooBig":false,"collapsed":false,"isSubmodule":false,"lineCount":2913,"linesChanged":4,"newTreeEntry":{"lineCount":2913,"path":"C++/chapLinearList.tex","mode":100644,"isGenerated":false},"oldTreeEntry":{"lineCount":0,"path":"C++/chapLinearList.tex","mode":100644},"linesAdded":2,"linesDeleted":2,"path":"C++/chapLinearList.tex","pathDigest":"974db70fbfffc21c388b822ffcafdb069fb47c70c52f57decf49d982df404c8d","status":"MODIFIED","truncatedReason":null,"oldOid":"f3a597e0e565676db4f771e4d841cdb0ed192ab6","newOid":"fb62b9578ae645188db52bcb52d72ff356367060","copilotChatReference":null,"deletedSha":"f3a597e0e565676db4f771e4d841cdb0ed192ab6","canToggleRichDiff":false,"defaultToRichDiff":false,"proseDifffHtml":null,"renderInfo":null,"dependencyDiffPath":null,"submodule":null}],"splitViewPreference":"unified","ignoreWhitespace":false,"commentsPreference":"visible","diffLineSpacingPreference":"relaxed","useMonospaceFont":false,"pasteUrlLinkAsPlainText":false,"userNotices":[],"path":"/nationcall/leetcode/commit/fb62b9578ae645188db52bcb52d72ff356367060","fileTreeExpanded":true,"headerInfo":{"additions":2,"deletions":2,"filesChanged":1,"filesChangedString":"1"},"moreDiffsToLoad":false,"asyncDiffLoadInfo":{"startIndex":1,"truncated":false,"byteCount":732,"lineShownCount":18},"commentInfo":{"canComment":false,"locked":false,"canLock":false,"repoArchived":false},"csrf_tokens":{"/users/diffview?diff=split":{"post":"R2xJWU_4KuU9VMe4QqwS2BoyLm8aJPDgvTMX7Uiz62W0mR-mRVD9iVcAc2dIkNfSaZZ_VdtJQsTWY6mr1iMWLA"},"/users/diffview?diff=unified":{"post":"5ZkqfwWUAag-PbHeKCzOGBZHjd0DOMoYJM0xWzvm7_cWbHyADzzWxFRpBQEiEAsSZePc58JVeDxPnY8dpXYSvg"},"/notifications/thread":{"post":"LpsvoHm3j-V3le-Dbn3Q1ep1-Vkkd4wqQYs9_d6bPU1t4NhyEKFe_F_MHvMOq5R_jK1E87KvqhphFfYOCfbKiA"}}},"title":"the sum of two integer may overflow. see · nationcall/leetcode@fb62b95","appPayload":{"helpUrl":"https://docs.github.com","findInDiffWorkerPath":"/assets-cdn/worker/find-in-diff-worker-f6b2312e7da9.js","enabled_features":{"diff_ux_refresh_beta":false,"diff_inline_comments":false,"diff_ux_refresh_ssr_five":false,"diff_ux_refresh_ssr_ten":false}}}

Commit fb62b95

Browse files
committed
1 parent f3a597e commit fb62b95

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

C++/chapLinearList.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ \subsubsection{代码}
182182
int search(int A[], int n, int target) {
183183
int first = 0, last = n;
184184
while (first != last) {
185-
const int mid = (first + last) / 2;
185+
const int mid = first + (last - first) / 2;
186186
if (A[mid] == target)
187187
return mid;
188188
if (A[first] <= A[mid]) {
@@ -240,7 +240,7 @@ \subsubsection{代码}
240240
bool search(int A[], int n, int target) {
241241
int first = 0, last = n;
242242
while (first != last) {
243-
const int mid = (first + last) / 2;
243+
const int mid = first + (last - first) / 2;
244244
if (A[mid] == target)
245245
return true;
246246
if (A[first] < A[mid]) {

0 commit comments

Comments
 (0)
0