刘拾柒的个人博客

健康、成长、赚钱

Algorithm

1313. 解压缩编码列表

解法一:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public int[] decompressRLElist(int[] nums) {
int resultLength = 0;
int loop = nums.length / 2;
// 计算目标数组的长度
for (int i = 0; i < loop; i++) {
resultLength += nums[2 * i];
}
// 执行解码操作
int[] result = new int[resultLength];
int resultIndex = 0;
for (int i = 0; i < loop; i++) {
for (int j = 0; j < nums[2 * i]; j++) {
result[resultIndex] = nums[2 * i + 1];
resultIndex++;
}
}
return result;
}
}

执行用时:1ms,内存消耗:37.8MB。

阅读全文 »

Algorithm

1295. 统计位数为偶数的数字

题解:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public int findNumbers(int[] nums) {
int count = 0;
for (int num : nums) {
int bits = 0;
do {
num = num / 10;
bits++;
} while (num != 0);

if (bits % 2 == 0) {
count++;
}
}

return count;
}
}

执行用时:1ms,内存消耗:38.7MB。

阅读全文 »

Algorithm

1304. 和为零的N个唯一整数

解法一:

钻了个漏洞。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public int[] sumZero(int n) {
if (n <= 1) {
return new int[]{0};
}

int[] result = new int[n];
int initNumber = 1, sum = 0;

for (int i = 0; i < n - 1; i++) {
result[i] = initNumber;
sum += initNumber;
initNumber++;
}

result[n - 1] = -sum;
return result;
}
}

执行用时:0ms,内存消耗:34.9MB。

阅读全文 »

打卡这么简单的事, 真的能影响到我?

背景

ARTS 起源于 陈皓 老师的 左耳听风 课程, 我们在其基础上做了一丢丢改造, 感谢 陈皓 老师.

两个月前, 我的朋友 大蕉 发起了一个为期 8 周的 ARTS 打卡活动:

每周打卡,自行创建一个博客地址。

打卡要求:
8人8周为一个小组。入群门槛188,8周完成全额退款,若全员完成,大蕉发188红包。

一周没打卡,请发10*当前人数红包一个。
两周没打卡,请退群。

打卡条件:
大家自发每周完成一个ARTS:
(也就是 Algorithm、Review、Tip、Share 简称ARTS)

(高级打卡组)
1.每周至少做一个 leetcode 的算法题
2.阅读并点评至少一篇英文技术文章
3.学习至少一个技术技巧(编程或其他)
4.编写一篇有观点和思考的技术文章(500字以内)

(初级打卡组)
1.每周至少做一个 leetcode 的算法题或者小玩具代码
2.阅读至少一篇英文技术文章
4.编写一篇文章(500字以内)

入群流程:
转账即报名,请描述自己想进入初级还是高级组

承诺:
我不承诺你一定能坚持下去,但我承诺你坚持下去肯定会看见不一样的自己

乍一看, 似乎很简单, 也似乎很难.

一咬牙, 我加入了这个计划.

阅读全文 »

Algorithm

1252. 奇数值单元格的数目

解法一

思路:

因为题目中行列式每次数据变换都是整行或者整列同时进行的, 所以只需要统计每一行和每一列会被自增多少次即可. 最后对应行和列的统计结果相加即为对应坐标的数值.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public int oddCells(int n, int m, int[][] indices) {
int[] rows = new int[n];
int[] columns = new int[m];
for (int[] axis : indices) {
rows[axis[0]]++;
columns[axis[1]]++;
}

int oddNumber = 0;
for (int row : rows) {
for (int column : columns) {
if ((row + column) % 2 == 1) {
oddNumber++;
}
}
}

return oddNumber;
}
}

执行用时: 1ms, 内存消耗: 38.7MB.

阅读全文 »
0%