Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 思考:快慢指針,快指針一次走兩步,慢指針一次一步。若快指針跟慢指針指向同一個結點,則有環。若快指針到達鏈表末尾即指向NULL
Intersection of Two Linked Lists: 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 leetcode121,begin to intersect at
1.題目描述 ? Implement int sqrt(int x). ? Compute and return the square root of x. LEETCODE。2.解法分析 很明顯,用二分搜索可解,但是需要防止溢出,所以中間結果和上界下界都要用long long 來保存。 class Solution { public: int sqrt(int x) { /
題目: A message containing letters from?A-Z?is being encoded to numbers using the following mapping: 'A' -> 1
'B' -> 2
...
'Z' -> 26 Given an encoded message containing digits, determine the total number of ways to
題目描述: Given an integer, write a function to determine if it is a power of two. ? 要完成的函數: bool isPowerOfTwo(int n)? ? 說明: 1、給定一個int型整數,判斷它是不是2的冪。首先我們可以確定負數和0都不是2的冪。1是2的0次冪。 2、如