缓存与数据库数据一致性问题,可以先更新数据库之后解析数据库的BINLOG更新缓存 :
博文:https://blog.csdn.net/striveb/article/details/95110502
binlog解析工具:https://github.com/javartisan/open-replicator
MYSQL数据库的binlog格式:https://dev.mysql.com/doc/internals/en/event-meanings.html
共同好友问题 :每一个用户维护一个关注set与被关注set,每次添加关注时候计算一下是否是共同好友,如果是的话,添加到共同好友列表中。
https://segmentfault.com/q/1010000000501071
https://www.jb51.net/article/54774.htm
import java.util.ArrayList;
import java.util.List;
class Test {
public List<String> random(int[] nums, int cnt, boolean isPaiLie) {
List<String> an = new ArrayList<>();
StringBuilder sb = new StringBuilder();
byte[] mtx = new byte[nums.length];
if (isPaiLie)
random(nums, mtx, cnt, an, sb);
else
random(nums, mtx, cnt, an, sb, 0);
return an;
}
public void random(int[] nums, byte[] mtx, int cnt, List<String> list, StringBuilder sb) {
if (cnt == 0) {
list.add(sb.toString());
}
for (int i = 0; i < nums.length; i++) {
if (mtx[i] == 1)
continue;
mtx[i] = 1;
String str = nums[i] + ";";
sb.append(str);
cnt--;
random(nums, mtx, cnt, list, sb);
cnt++;
sb.delete(sb.length() - str.length(), sb.length());
mtx[i] = 0;
}
}
public void random(int[] nums, byte[] mtx, int cnt, List<String> list, StringBuilder sb, int index) {
if (cnt == 0) {
list.add(sb.toString());
}
for (int i = index; i < nums.length; i++) {
if (mtx[i] == 1)
continue;
mtx[i] = 1;
String str = nums[i] + ";";
sb.append(str);
cnt--;
random(nums, mtx, cnt, list, sb, i);
cnt++;
sb.delete(sb.length() - str.length(), sb.length());
mtx[i] = 0;
}
}
public static void main(String[] args) {
System.out.println(new Test().random(new int[]{-2, 1, 3}, 2, false));
}
}