程序员面试金典——5.8像素设定
参考网址:https://www.nowcoder.com/questionTerminal/31ade926268441878d423029c54f5171
链接:https://www.nowcoder.com/questionTerminal/31ade926268441878d423029c54f5171
来源:牛客网
/*
基本上大意就是从第x 到第y位 ,其中的像素全部变为0,如此两种情况 :
0-->1, 1-->1 ,所以这时候就很清楚的用 位操作中的 ' | '
*/
vector<int> renderPixel(vector<int> screen, int x, int y) {
for(int i = x ; i <= y ; i ++) {
//找到位于某元素的哪一位?
int k = i % 8 ;
//找到是哪一个元素
int t = i / 8 ;
screen[t] = screen[t] | (1<< k);
}
return screen;
}