We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
题解思路简要概括为:借位运算解构棋子移动,BFS求解最短路径问题。
详见 题解博客 与 题解源码 。有什么想说的?快来一起讨论吧!
在 题解博客 - 棋局压缩 一节的末尾,留下了几点思考
1
long
visited
Set<Long>
在 题解博客 - 抽象优化 一节中,只是简要表达了可优化的方向。你有更好的优化切入点吗?
The text was updated successfully, but these errors were encountered:
找最低位 1 的位置,是试着逐个位右移后,每次都判断移后最低位是否为 1 ,更好的写法是?
可通过 temp[i] & -temp[i] 取最低位 1 后,再对数所得
temp[i] & -temp[i]
long lowest = log2(temp[i] & -temp[i]); private static int log2(int n) { if (n <= 0) throw new IllegalArgumentException(); return 31 - Integer.numberOfLeadingZeros(n); }
补充知识: x & -x 指的是取最低位的 1 及后面的所有 0。
x & -x
0
int x = 0b10010110101011000; int lowest = x & -x; // 1000,最低位的1及后面的0
Sorry, something went wrong.
No branches or pull requests
题解思路简要概括为:借位运算解构棋子移动,BFS求解最短路径问题。
详见 题解博客 与 题解源码 。有什么想说的?快来一起讨论吧!
在 题解博客 - 棋局压缩 一节的末尾,留下了几点思考
1
的位置,是试着逐个位右移后,每次都判断移后最低位是否为1
,更好的写法是?long
,但判重的哈希集合visited
类型为Set<Long>
,意味着存在装箱、拆箱,可有更好方案?在 题解博客 - 抽象优化 一节中,只是简要表达了可优化的方向。你有更好的优化切入点吗?
The text was updated successfully, but these errors were encountered: