lc面试准备:Power of Two】的更多相关文章

1 题目 Given an integer, write a function to determine if it is a power of two. 接口 boolean isPowerOfTwo(int n) 2 思路 判断一个整数是否是2的幂次结果数. 0100 ==> 4 : 1000 ==>8 : 10000 ==> 16 0011 ==> 3 : 0111 ==>7 : 01111 ==> 15 思路1:2的次方数都只有一个1,剩下的都是0.我们只要每次…
1 题目 Given a sorted linked list, delete all duplicates such that each element appear only once. For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return 1->2->3. 接口 ListNode deleteDuplicates(ListNode head) 简单的链表操作的题目,要…
Starting with a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is not zero. Return true if and only if we can do this in a way such that the resulting number is a power of 2. Example…
1 题目 Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. pop() -- Removes the element on top of the stack. top() -- Get the top element. empty() -- Return whether the stack is empty. **Notes:** You must u…
1 题目 Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element. empty() -- Return whether the queue is empty. **Not…
1 题目 Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 接口: public TreeNode invertTree(TreeNode root) 2 思路 反转一颗二叉树. 可以用递归和非递归两种方法来解. 递归的方法,写法非常简洁,五行代码搞定,交换当前左右节点,并直接调用递归即可. 非递归的方法,参考树的层序遍历,借助Queue来辅助,先把根节点排入队列中,然后从队中取出来,交换其左…
1 题目 All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Write a function to find all the 10-letter-lon…
1 题目 Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit integer ’11' has binary representation 00000000000000000000000000001011, so the function should…
1 题目 Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000). Follow up:If this funct…
1 题目 Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype shou…