69. Sqrt(x)
Implement int sqrt(int x).
Compute and return the square root of x.
x is guaranteed to be a non-negative integer.
Example 1:
Input: 4
Output: 2
Example 2:
Input: 8
Output: 2
Explanation: The square root of 8 is 2.82842..., and since we want to return an integer, the decimal part will be truncated.
這題我只想到暴力解,所以就直接放棄看解答了,解法非常有趣
用BFS,不斷逼近正確的區段,因為有可能不是整數,最後確定數值是用 if(mid+1 > x/(mid+1)) 來判斷 (來確定下個值會過大,正解就是這個值)
angledark0123 發表在 痞客邦 留言(0) 人氣(17)
17. Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent.
A mapping of digit to letters (just like on the telephone buttons) is given below.
angledark0123 發表在 痞客邦 留言(0) 人氣(32)
88. Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.
angledark0123 發表在 痞客邦 留言(0) 人氣(16)
234. Palindrome Linked List
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?
angledark0123 發表在 痞客邦 留言(0) 人氣(6)
283. Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.
angledark0123 發表在 痞客邦 留言(0) 人氣(13)
92. Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.
angledark0123 發表在 痞客邦 留言(0) 人氣(22)
13. Roman to Integer
Given a roman numeral, convert it to an integer.
Input is guaranteed to be within the range from 1 to 3999.
angledark0123 發表在 痞客邦 留言(0) 人氣(12)
173. Binary Search Tree Iterator
這題題意有點模糊,一開始我作成preorder sort 還過了
angledark0123 發表在 痞客邦 留言(0) 人氣(15)
29. Divide Two Integers
Divide two integers without using multiplication, division and mod operator.
If it is overflow, return MAX_INT.
angledark0123 發表在 痞客邦 留言(0) 人氣(13)
33. Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.
(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).
angledark0123 發表在 痞客邦 留言(0) 人氣(5)