# Arts 第八十五周（5/31 ～ 6/6）

ARTS是什么？
Algorithm：每周至少做一个leetcode的算法题；
Review：阅读并点评至少一篇英文技术文章；
Tip：学习至少一个技术技巧；
Share：分享一篇有观点和思考的技术文章。

## Algorithm

LC 763. Partition Labels

``````public List<Integer> partitionLabels(String s) {
int[] counts = new int[26];
List<Integer> results = new ArrayList<>();
Set<Character> rep = new HashSet<>();

for (char c : s.toCharArray()) {
counts[c - 'a']++;
}

int len = 0;
for (char c : s.toCharArray()) {
len++;
if (counts[c - 'a']-- == 1) {
rep.remove(c);
} else {
}

if (rep.isEmpty()) {
len = 0;
}
}

return results;
}

``````public List<Integer> partitionLabels(String s) {
List<Integer> results = new ArrayList<>();
int[] lastIndex = new int[26];

for (int i = 0; i < s.length(); ++i) {
lastIndex[s.charAt(i) - 'a'] = i;
}

int maxLastIndex = 0, start = 0;
for (int i = 0; i < s.length(); ++i) {
maxLastIndex = Math.max(maxLastIndex, lastIndex[s.charAt(i) - 'a']);

if (i == maxLastIndex) {
start = i + 1;
}
}

return results;
}

## Review

Signs that You are a Bad Programmer

## Tip

``````const net = require('net');

const server = net.createServer();

server.listen(3326, () => {
console.log('TCP Server is listening');
});

server.on('connection', (socket) => {
// 读取数据
socket.on('data', (buffer) => {
const msg = buffer.toString();
console.log(msg);

// write 方法写入数据，发回给客户端
// socket.write(Buffer.from(`你好 Pyh`));
});
});

server.on('close', () => {
console.log('Server Close!');
});

server.on('error', (err) => {
console.error('服务器异常：', err);
});

``````const net = require('net');

const client = net.createConnection({
host: '127.0.0.1',
port: 3326,
});

client.on('connect', () => {
// 向服务器发送数据
client.write('Nodejs 技术栈');
client.end();
});

client.on('data', (buffer) => {
console.log(buffer.toString());
});

client.on('error', (err) => {
console.error('服务器异常：', err);
});

client.on('close', (err) => {
console.log('客户端链接断开！', err);
});