作者w199381 (噁心肥宅)
看板C_Sharp
標題[問題] 程式碼看不懂..
時間Thu Mar 29 08:45:54 2018
自學刷leetcode中 看人家解答 但是一句不明
StringBuilder sb = new StringBuilder();
int carry = 0;
for (int i = a.Length - 1, j = b.Length - 1; i >= 0 || j >= 0; i--, j--){
int total= ((i >= 0 ? a[i] - '0' : 0) + (j >= 0 ? b[j] - '0' : 0)) + carry;
sb.Insert(0, total == 2 || total == 0 ? '0' : '1');
carry = total > 1 ? 1 : 0;
}
想請問其中的 a[i]-‘0’,b[j]-‘0’ 是什麼意思 google 很久查不到...
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 27.247.193.205
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1522284356.A.E21.html
→ petercoin: 減掉0x30的意思吧? 03/29 08:47
推 jerryh001: ascii 碼相減 相當於文字轉數字 03/29 09:54
→ smmoon: 這解答看起來相當____ 03/29 11:32
推 johnny94: 裝B 04/04 10:45