刚二面滴滴的时候,面试老师出了一道如标题的题目。
面试的时候比较慌张,跟着老师的引导就只答出了递归的方法。
不过面完折腾出一个新方法:
( (int)( &((uint8_t (*) [n])0)[1+n][0]) ) >> 1;
更多解法: https://github.com/gatieme/CodingInterviews/tree/master/046-求1%2B2%2B3%2B...%2Bn
面试的时候比较慌张,跟着老师的引导就只答出了递归的方法。
不过面完折腾出一个新方法:
( (int)( &((uint8_t (*) [n])0)[1+n][0]) ) >> 1;
更多解法: https://github.com/gatieme/CodingInterviews/tree/master/046-求1%2B2%2B3%2B...%2Bn