Hello World1
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick StartCreate a new post1$ hexo new "My New Post"
More info: Writing
Run server1$ hexo server
More info: Server
Generate static files1$ hexo generate
More info: Generating
Deploy to remote sites1$ hexo deploy
More info: Deployment
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick StartCreate a new post1$ hexo new "My New Post"
More info: Writing
Run server1$ hexo server
More info: Server
Generate static files1$ hexo generate
More info: Generating
Deploy to remote sites1$ hexo deploy
More info: Deployment
将矩阵按对角线排序
题目矩阵对角线 是一条从矩阵最上面行或者最左侧列中的某个元素开始的对角线,沿右下方向一直到矩阵末尾的元素。例如,矩阵 mat 有 6 行 3 列,从 mat[2][0] 开始的 矩阵对角线 将会经过 mat[2][0]、mat[3][1] 和 mat[4][2] 。
给你一个 m * n 的整数矩阵 mat ,请你将同一条 矩阵对角线 上的元素按升序排序后,返回排好序的矩阵。
示例 1:
输入:mat = [[3,3,1,1],[2,2,1,2],[1,1,1,2]]输出:[[1,1,1,1],[1,2,2,2],[1,2,3,3]]
示例 2:
输入:mat = [[11,25,66,1,69,7],[23,55,17,45,15,52],[75,31,36,44,58,8],[22,27,33,25,68,4],[84,28,14,11,5,50]]输出:[[5,17,4,1,52,7],[11,11,25,45,8,69],[14,23,25,44,58,15],[22,27,31,36,50,66],[84,28,75,33,55,68]]
提示:
m == mat. ...
负二进制转换
题目给你一个整数 n ,以二进制字符串的形式返回该整数的 负二进制(base -2) 表示。
注意,除非字符串就是 "0",否则返回的字符串中不能含有前导零。
示例 1:
输入:n = 2输出:”110”解释:(-2)^2^ + (-2)^1^ = 2
示例 2:
输入:n = 3输出:”111”解释:(-2)^2^ + (-2)^1^ + (-2)^0^ = 3
示例 3:
输入:n = 4输出:”100”解释:(-2)^2^ = 4
提示:
0 <= n <= 109
题解10进制中314写成314是3 * 10^2^ + 1 * 10^1^ + 4 * 10^0^。所以2的二进制是10,1 * 2^1^ + 0 * 2^0^, 2的负二进制是110, 1*(-2)^2^ + 1*(-2)^1^ + 0*(-2)^0^。十进制转二进制方法是 除2取余数逆序排序。
被除数
除数
商
余数
2
2
1
0
1
2
0
1
2的负二进制为( ...
快照数组
题目实现支持下列接口的「快照数组」- SnapshotArray:
SnapshotArray(int length) - 初始化一个与指定长度相等的 类数组 的数据结构。初始时,每个元素都等于 0。
void set(index, val) - 会将指定索引 index 处的元素设置为 val。
int snap() - 获取该数组的快照,并返回快照的编号 snap_id(快照号是调用 snap() 的总次数减去 1)。
int get(index, snap_id) - 根据指定的 snap_id 选择快照,并返回该快照指定索引 index 的值。
示例:
123456789输入:["SnapshotArray","set","snap","set","get"] [[3],[0,5],[],[0,6],[0,0]]输出:[null,null,0,null,5]解释:SnapshotArray snapshotArr = new SnapshotArray(3); // ...

