算法
文章平均质量分 57
迅丶
我机智的一匹
展开
-
【LeetCode】521. Longest Uncommon Subsequence I
521. Longest Uncommon Subsequence IProblemExampleSolutionProblem最长 不公共 子串Example输入:“aba”, “cdc”输出:3解释:左子串的最长子串为自己,右边也是,他们不相等,所以为3输入:“asdf”,“asd”输出:3解释:左边最长字串为自己长度为4,右边最长为自己,长度为3,最长的不公共字串就为...原创 2018-12-26 21:43:16 · 94 阅读 · 0 评论 -
【LeetCode】226. Invert Binary Tree
226. Invert Binary TreeProblemExampleSolutionProblem翻转二叉树Example输入: 4 / \ 2 7 / \ / \1 3 6 9输出: 4 / \ 7 2 / \ / \9 6 3 1Solution递归的交换左右子树/**...原创 2018-12-25 23:02:12 · 94 阅读 · 0 评论 -
Tree
树的遍历前序遍历中序遍历后序遍历“什么序” 遍历,对当前节点的操作就在“什么位置”前序遍历 public void preorderTraversal(TreeNode root){ if (root != null) { System.out.println(root.val); preorderTraversal(root.left); preorderTra...原创 2018-12-25 21:52:10 · 130 阅读 · 0 评论 -
【LeetCode】693. Binary Number with Alternating Bits
693. Binary Number with Alternating BitsProblemExampleSolutionProblem给一个正整数,判断他的二进制形式 是否是0,1交替的Example5(101) true7(111) false10(1010) true11(1011)falseSolution如果是最低位为0,如1010,先右移一位,方便计算...原创 2018-12-25 21:34:11 · 94 阅读 · 0 评论 -
【LeetCode】762. Prime Number of Set Bits in Binary Representation
Prime Number of Set Bits in Binary RepresentationProblemExampleSolution一堆题放一块太挤了,还是分开放=.=,也能写得详细一点Problem求[L,R]这个闭区间内的数字 二进制表示形式 1的个数 为素数 的数量ExampleL = 6, R = 106(0101),1的个数为2,2是素数 +17(1001)...原创 2018-12-24 21:37:37 · 134 阅读 · 0 评论 -
【LeetCode】Day5
文章目录412. Fizz Buzz953. Verifying an Alien Dictionary566. Reshape the Matrix104. Maximum Depth of Binary Tree136. Single Number429. N-ary Tree Level Order Traversal637. Average of Levels in Binary Tree...原创 2018-12-23 18:43:02 · 138 阅读 · 0 评论 -
数字字符串运算
文章目录500. Keyboard Row872. Leaf-Similar Trees893. Groups of Special-Equivalent Strings500. Keyboard RowGiven a List of words, return the words that can be typed using letters of alphabet on only one ...原创 2018-12-11 21:32:34 · 563 阅读 · 0 评论 -
【LeetCode】896. Monotonic Array
896. Monotonic ArrayProblemExampleSolutionProblem判断一个数组是否为单调不减或单调不增数组。i <= j ,A[i] <= A[j]或i >= j , A[i] >= A[j]ExampleInput: [1,2,2,3]Output: trueInput: [6,5,4,4]Output: tru...原创 2018-12-27 00:15:38 · 115 阅读 · 0 评论 -
【LeetCode】892. Surface Area of 3D Shapes
892. Surface Area of 3D ShapesProblemExampleSolutionProblem求3D图形的表面积。二维数组v = grid[i][j],v表示图形的高,(i,j)表示所在的格子位置Example输入:[[2]]输出:10解释: 3D图形有4个侧面,面积都一样,两个上下面。S = 4 * h(高)+ 2 * 1输入:[[1,2],[3,4...原创 2018-12-26 23:19:57 · 140 阅读 · 0 评论 -
【LeetCode】292. Nim Game
292. Nim GameProblemExampleSolutionProblem你和朋友在玩一个游戏,桌上有一堆石头,你俩每次轮流拿走1到3个石头,拿走最后剩余石头的就是赢家。你先开始拿。你俩都很聪明,会选最佳策略。写一个方法,初始有多少个石头,你会赢。Example输入:4输出:false解释:不管你拿1,2,3个石头,剩下3,2,1个石头都会被朋友一次性拿光,所以输。...原创 2018-12-26 21:59:53 · 286 阅读 · 0 评论 -
【LeetCode】917. Reverse Only Letters
917. Reverse Only LettersProblemExampleSolutionProblem给一个字符串,只反转其中的字母ExampleInput: “ab-cd”Output: “dc-ba”Input: “a-bC-dEf-ghIj”Output: “j-Ih-gfE-dCba”Input: “Test1ng-Leet=code-Q!”Outpu...原创 2018-12-25 23:24:04 · 131 阅读 · 0 评论