1. 问题出在for循环中,应该将i>0改为i>=0
a) 输入x为空数组,不执行fault部分
b) 测试用例:x = [1, 2, 3] ; y = 3 此时执行了fault但没有引发error,因为直接返回了3。
c) 测试用例:x = [1, 2, 3] ; y = 0 此时执行了fault并引发了error但从外部看,结果上并没有出错。
2. 问题在于这段代码是寻找第一个0的位置,而要求是寻找最后一个0出现的位置。
a) 输入x为空数组,不执行fault部分
b) 测试用例:x = [0] 此时执行了fault但没有引发error
c) 测试用例:x = [1, 2] 此时出现了error但结果上并没有出错。
原文:http://www.cnblogs.com/LexDice/p/6490498.html