题解 | 像素设定

像素设定

https://www.nowcoder.com/practice/31ade926268441878d423029c54f5171

#include <iterator>
class Render {
public:
    vector<int> renderPixel(vector<int> screen, int x, int y) {
        // write code here
        int start_idx = x/8;
        int end_idx = y/8;
        int start_bit = 0xFF << (x%8)  & 0xFF;
        int end_bit = (1 << (y%8 +1 ) ) -1;

       
        if(start_idx == end_idx){
            screen[start_idx] |= start_bit & end_bit;
            return screen;
        }
        screen[start_idx] |= start_bit ;
        screen[end_idx] |= end_bit;

        for(int i = start_idx+1 ; i <end_idx;++i){
            screen[i] = 0xFF;
        }
        return screen;


    }
};

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务