# Category Archives: Number trick

## String to Integer (atoi)

Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be … Continue reading

Posted in Number trick, String | Leave a comment

## Integer to Roman

Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. C++: 01 class Solution { 02 public: 03     string intToRoman(int num) { 04         // Start typing your … Continue reading

Posted in Number trick, String | Leave a comment

## Roman to Integer

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. C++: 01 class Solution { 02 public: 03     int romanToInt(string s) { 04         // Start typing your … Continue reading

Posted in Number trick, String | Leave a comment

## Palindrome Number

Determine whether an integer is a palindrome. Do this without extra space. C++: 01 class Solution { 02 public: 03     bool isPalindrome(int x) { 04         // Start typing your C/C++ solution below 05         // DO … Continue reading

Posted in Number trick | Leave a comment

## Reverse Integer

Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 C++: 01 class Solution { 02 public: 03     int reverse(int x) { 04         // Start typing your C/C++ solution below 05      … Continue reading

Posted in Array and linked list, Number trick | Leave a comment

## Multiply Strings

Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. C++: 001 string shift(string s,int t) 002 { 003     if(s==“0”) 004         return s; 005  … Continue reading

Posted in Number trick, Stack and Queue, String | Leave a comment

## Pow(x, n)

Implement pow(x, n). C++: 01 class Solution { 02 public: 03     double pow(double x, int n) { 04         // Start typing your C/C++ solution below 05         // DO NOT write int main() function 06    … Continue reading

Posted in Number trick, Recursive | Leave a comment