
算法
Valars
壁立千仞,无欲则刚
展开
-
Java实现全排列
全排列是将一组数(非重复)按一定顺序进行排列,如果这组数有n个,那么全排列数为n!个。可以采用递归的方式实现。 public class Perm{ static numPerm=0; public static void main(String[] args){ Perm perm=new Perm(); String[]原创 2017-06-05 16:13:52 · 388 阅读 · 0 评论 -
【LeetCode】Swap Nodes in Pairs
java实现的LeetCode中交换链表中相邻的值 public class SwapNodes{ public ListNode swapPairs(ListNode head){ ListNode aidNode=new ListNode(0); aidNode.next=head; ListNode currentNo...转载 2017-04-19 22:53:10 · 410 阅读 · 0 评论 -
逆序对(字符串,只包含ABCD字符)
[题目]字符串S中,只包含字符'A'/'B'/'C'/'D', 求字符串S中的逆序对. public class ReverseOrder { public static void main(String[] args { int aa = reverseNums("DBCBBA"); System.out.println(aa); } public static int ...原创 2017-04-04 07:58:44 · 1867 阅读 · 0 评论 -
求二叉排序树的最小公共根
[题目]给定一棵深度为K的二叉排序树, 求a和b(a >= b)的最小公共根. public class Solve { public static void main(String[] args) { int aa=minRoot(4, 10, 13); int bb=minRoot(4, aa, 15); System.out.println(bb); } ...原创 2017-04-04 07:39:09 · 2266 阅读 · 0 评论