作者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://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1522284356.A.E21.html
1F:→ petercoin: 减掉0x30的意思吧? 03/29 08:47
2F:推 jerryh001: ascii 码相减 相当於文字转数字 03/29 09:54
3F:→ smmoon: 这解答看起来相当____ 03/29 11:32
4F:推 johnny94: 装B 04/04 10:45