142. O(1) Check Power of 2【easy】】的更多相关文章

142. O(1) Check Power of 2[easy] Using O(1) time to check whether an integer n is a power of 2. Have you met this question in a real interview? Yes Example For n=4, return true; For n=5, return false; Challenge O(1) time 解法一: class Solution { public:…
Description Using O(1) time to check whether an integer n is a power of 2. Example For n=4, return true; For n=5, return false; Challenge O(1) time 题解:题目要求判断一个数是不是2的幂次方,并且规定时间复杂度为线性级.那么,就不能用常规的循环求解思路去解题了,之前做过一个不用加号求两数之和的题目.这两个题目有点类似,可以通过位运算来快速求解.先考虑这…
142. Linked List Cycle II[easy] Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up:Can you solve it without using extra space? 解法一: /** * Definition for singl…
160. Intersection of Two Linked Lists[easy] Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3 begin to intersect at n…
234. Palindrome Linked List[easy] Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it in O(n) time and O(1) space? 解法一: /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * Lis…
27. Remove Element[easy] 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 be ch…
459. Repeated Substring Pattern[easy] Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters o…
170. Two Sum III - Data structure design[easy] Design and implement a TwoSum class. It should support the following operations:add and find. add - Add the number to an internal data structure.find - Find if there exists any pair of numbers which sum…
206. Reverse Linked List[easy] Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. Could you implement both? 解法一: class Solution { public: ListNode* reverseList(ListNode* head) { ListNode * pre = NULL;…
203. Remove Linked List Elements[easy] Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5 Credits:Special than…