Leetcode算法练习##
easy篇-Reverse Integer
最近正式入驻Leetcode,从今天开始会陆陆续续的整理在Leetcode 上的题目,用于笔记的整理与交流,而且除了自己的做法之外还会整理一些其他的好算法,并进行简单的分析与分享,考虑到算法的训练并不多,希望大家可以多多包涵。
题目要求:
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
click to show spoilers.
Note:
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.
题目不难,但我的做法比较扭曲。。。
int reverse(int x) {
int _[1000] = {0};
int i = 0,j =0, k =0;
int count = x;
int ret = 0,sum = 1;
if(x > 0)
{
for(i = 1; count >= 10; i++)
{
_[i] = count % 10;
count = count / 10;
}
_[i] = count;
for(k = 1