【LeetCode】Power of Two】的更多相关文章

问题描写叙述 Given an integer, write a function to determine if it is a power of two. 意:推断一个数是否是2的n次幂 算法思想 假设一个数小于或等于0.一定不是2的幂次数 假设一个大于0且数是2的n次幂,则其的二进制形式有且仅有一个1,反之成立. 算法实现 public class Solution { public boolean isPowerOfTwo(int n) { if(n<=0) return false;…
[2]Add Two Numbers (2018年12月23日,review) 链表的高精度加法. 题解:链表专题:https://www.cnblogs.com/zhangwanying/p/9797184.html [7]Reverse Integer (2018年12月23日, review) 给了一个32位的整数,返回它的reverse后的整数.如果reverse后的数超过了整数的范围,就返回 0. Example 1: Input: 123 Output: 321 Example 2:…
[78]Subsets 给了一个 distinct 的数组,返回它所有的子集. Example: Input: nums = [,,] Output: [ [], [], [], [,,], [,], [,], [,], [] ] 题解:我是直接dfs(backtracking)了,有个小地方写错了(dfs那里),至少调整了十多分钟,下次不要写错了. class Solution { public: vector<vector<int>> subsets(vector<int…
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 回溯法 日期 题目地址:https://leetcode.com/problems/subsets-ii/description/ 题目描述 Given a collection of integers that might contain duplicates, nums, return all possible subsets (the po…
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 递归和非递归,此提比较简单.广度优先遍历即可.关键之处就在于如何保持访问深度. 下面是4种代码: im…
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Return [1,3,3,1]. Note: Could you optimize your algorithm to use only O(k) extra space? 思路:最简单的方法就是依照[Leetcode]Pascal's Triangle 的方式自顶向下依次求解,但会造成空间的浪费.若仅仅用一个vect…
53. Maximum Subarray[leetcode] Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4],the contiguous subarray [4,-1,2,1] has the largest sum = 6. 挑…
27. Remove Element[leetcode] Given an array and a value, remove all instances of that value in place and return the new length. Do not allocate extra space for another array, you must do this in place with constant memory. The order of elements can b…
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接-空 007-整数反转 方法: 弹出和推入数字 & 溢出前进行检查 思路: 我们可以一次构建反转整数的一位数字.在这样做的时候,我们可以预先检查向原整数附加另一位数字是否会导致溢出. 算法: 反转整数的方法可以与反转字符串进行类比. 我们想重复"弹出" x 的最后一位数字,并将它"推入"到 rev 的后面.最后,rev 将与 x 相反. 要在没有辅助堆栈 / 数组的帮助下…
[刷题][LeetCode]总 用动画的形式呈现解LeetCode题目的思路 参考链接 000-十大经典排序算法…