上一页 1 ··· 8 9 10 11 12 13 14 15 下一页
摘要: 解法一: f[i][j]表示数列A的前i个和数列B的前j个且以B[i]结尾的最长公共上升子序列 f[i][j]=f[i−1][j] (a[i]≠b[j]) f[i][j]=max(f[i−1][j],f[i−1][t]+1) (a[i]=b[j] 且 1 <= t < j) #include <io 阅读全文
posted @ 2020-07-11 16:01 Sexyomaru 阅读(105) 评论(0) 推荐(0)
摘要: 分析:暴力法是可以做的但是时间复杂度O(n2),竞赛选手很容易想到用线段树,树状数组来优化时间复杂度,这里贴几种容易理解的方法 方法一:归并排序,归并排序可以求逆序对,这是我们熟悉的,所以在归并排序的合并过程,我们可以求出右边小于当前数的有几个,这道题需要返回每个位置的右边小于它的元素数量,我们可以 阅读全文
posted @ 2020-07-11 13:26 Sexyomaru 阅读(130) 评论(0) 推荐(0)
摘要: class Solution { List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> levelOrder(TreeNode root) { dfs(root,1); return res; } public 阅读全文
posted @ 2020-07-10 11:27 Sexyomaru 阅读(101) 评论(0) 推荐(0)
摘要: 方法一:递归 class Solution { public boolean isSymmetric(TreeNode root) { if(root == null) return true; return isSame(root.left,root.right); } public boolea 阅读全文
posted @ 2020-07-10 11:19 Sexyomaru 阅读(72) 评论(0) 推荐(0)
摘要: class Solution { public ListNode reverseBetween(ListNode head, int m, int n) { if(m == 1) { ListNode node = reverse(head,n); return node; } head.next 阅读全文
posted @ 2020-07-10 10:39 Sexyomaru 阅读(77) 评论(0) 推荐(0)
摘要: #include <iostream> using namespace std; int main() { int a, b , p; cin >> a >> b >> p; int res = 1 % p; while(b) { if(b&1) res = res * 1ll * a % p; a 阅读全文
posted @ 2020-07-09 11:55 Sexyomaru 阅读(153) 评论(0) 推荐(0)
摘要: 知识点:格雷编码的生成过程, G(i) = i ^ (i/2); 如 n = 3: G(0) = 000, G(1) = 1 ^ 0 = 001 ^ 000 = 001 G(2) = 2 ^ 1 = 010 ^ 001 = 011 G(3) = 3 ^ 1 = 011 ^ 001 = 010 G(4 阅读全文
posted @ 2020-07-09 10:28 Sexyomaru 阅读(221) 评论(0) 推荐(0)
摘要: class Solution { public boolean isScramble(String s1, String s2) { int n = s1.length(); if(n == 0) return true; if(s1.equals(s2)) return true; int[] a 阅读全文
posted @ 2020-07-09 10:23 Sexyomaru 阅读(147) 评论(0) 推荐(0)
摘要: class Solution { public int respace(String[] dictionary, String sentence) { int n = sentence.length(); if(n == 0) return 0; Trie t = new Trie(); for(S 阅读全文
posted @ 2020-07-09 10:08 Sexyomaru 阅读(124) 评论(0) 推荐(0)
摘要: class Solution { public int countCornerRectangles(int[][] grid) { if(grid.length < 2 || grid[0].length < 2) return 0; int m = grid.length, n = grid[0] 阅读全文
posted @ 2020-07-08 21:32 Sexyomaru 阅读(261) 评论(0) 推荐(0)
上一页 1 ··· 8 9 10 11 12 13 14 15 下一页