69Sqrt(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) 人氣()

88Merge Sorted Array
Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

angledark0123 發表在 痞客邦 留言(0) 人氣()

 234Palindrome 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) 人氣()

283Move 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. 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) 人氣()

1
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。