随笔分类 -  LeetCode

摘要:给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。 回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 例如,121 是回文,而 123 不是。 示例 1: 输入:x = 121 输出:true 示例 2: 输入:x = -121 输出:false 阅读全文
posted @ 2022-09-13 13:59 六层楼 阅读(26) 评论(0) 推荐(0) 编辑
摘要:一、爬楼梯 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 注意:给定 n 是一个正整数。 示例 1: 输入: 2 输出: 2 解释: 有两种方法可以爬到楼顶。 1 阶 + 1 阶 2 阶 示例 2: 输入: 3 输出: 3 解 阅读全文
posted @ 2021-07-13 16:43 六层楼 阅读(176) 评论(0) 推荐(0) 编辑
摘要:X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be rotate 阅读全文
posted @ 2019-11-25 09:23 六层楼 阅读(221) 评论(0) 推荐(0) 编辑
摘要:A zero indexed array A consisting of N numbers is given. A slice of that array is any pair of integers (P, Q) such that 0 A = [1, 2, 3, 4] return: 3, 阅读全文
posted @ 2019-11-25 09:22 六层楼 阅读(173) 评论(0) 推荐(0) 编辑
摘要:Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a g 阅读全文
posted @ 2019-10-21 14:38 六层楼 阅读(159) 评论(0) 推荐(0) 编辑
摘要:Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right. Note that elements beyond 阅读全文
posted @ 2019-09-27 10:22 六层楼 阅读(415) 评论(0) 推荐(0) 编辑
摘要:Given an n ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example, given a 3 ary tree: 阅读全文
posted @ 2019-07-26 16:32 六层楼 阅读(203) 评论(0) 推荐(0) 编辑
摘要:Given the root node of a binary search tree (BST) and a value to be inserted into the tree, insert the value into the BST. Return the root node of the 阅读全文
posted @ 2019-02-05 22:44 六层楼 阅读(281) 评论(0) 推荐(0) 编辑
摘要:You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in Sis a type of stone 阅读全文
posted @ 2018-05-17 17:36 六层楼 阅读(202) 评论(0) 推荐(0) 编辑
摘要:Given an integer array with no duplicates. A maximum tree building on this array is defined as follow: The root is the maximum number in the array. Th 阅读全文
posted @ 2017-12-08 10:05 六层楼 阅读(326) 评论(0) 推荐(0) 编辑
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: Given , the answer is , which the length is 3. Given 阅读全文
posted @ 2017-11-28 11:16 六层楼 阅读(150) 评论(0) 推荐(0) 编辑
摘要:Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking num 阅读全文
posted @ 2017-07-11 12:48 六层楼 阅读(1412) 评论(0) 推荐(0) 编辑
摘要:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: Example 1: Exa 阅读全文
posted @ 2017-07-04 17:02 六层楼 阅读(462) 评论(0) 推荐(0) 编辑
摘要:与树的前中后序遍历的DFS思想不同,层次遍历用到的是BFS思想。一般DFS用递归去实现(也可以用栈实现),BFS需要用队列去实现。 层次遍历的步骤是: 1.对于不为空的结点,先把该结点加入到队列中 2.从队中拿出结点,如果该结点的左右结点不为空,就分别把左右结点加入到队列中 3.重复以上操作直到队列 阅读全文
posted @ 2017-07-03 09:22 六层楼 阅读(15158) 评论(2) 推荐(0) 编辑
摘要:Given a string containing only digits, restore it by returning all possible valid IP address combinations. For example:Given "25525511135", return ["2 阅读全文
posted @ 2017-03-23 16:10 六层楼 阅读(224) 评论(0) 推荐(0) 编辑
摘要:Given a binary tree, return thepreordertraversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3return[1,2,3].Not... 阅读全文
posted @ 2015-11-26 21:44 六层楼 阅读(169) 评论(0) 推荐(0) 编辑
摘要:Given an array ofnintegers wheren> 1,nums, return an arrayoutputsuch thatoutput[i]is equal to the product of all the elements ofnumsexceptnums[i].Solv... 阅读全文
posted @ 2015-10-18 13:34 六层楼 阅读(713) 评论(0) 推荐(0) 编辑
摘要:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 ston... 阅读全文
posted @ 2015-10-17 18:23 六层楼 阅读(139) 评论(0) 推荐(0) 编辑
摘要:Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to thedefinition of LCA on Wikipedia: ... 阅读全文
posted @ 2015-10-08 22:30 六层楼 阅读(154) 评论(0) 推荐(0) 编辑
摘要:Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired bythis... 阅读全文
posted @ 2015-10-06 18:53 六层楼 阅读(154) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示