摘要:
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.Code:class Solution {public: int romanToInt(string s) { int len=s.length(); map character; character['I'] = 1; character['V'] = 5; character['X'] = 10; ... 阅读全文
摘要:
Given a sorted array, remove the duplicates in place such that each element appear onlyonceand return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.For example,Given input array A =[1,1,2],Your function should return length =2, and A is 阅读全文
摘要:
Implementint sqrt(int x).Compute and return the square root ofx.Code:class Solution {public: int sqrt(int x) { int start=0; int end=x/2>std::sqrt(INT_MAX)?std::sqrt(INT_MAX):x/2+1; while(start<=end){ int mid=(start+end)/2; if(x==mid*mid) r... 阅读全文