public int reverse(int x) {
		int ret = 0;

		while (x != 0) {
			int tail = x % 10;
			int newResult = ret * 10 + tail;
			if ((newResult - tail) / 10 != ret) {
				return 0;	// avoid number too large and overflow (like 123242123211)
			}
			ret = newResult;
			x = x / 10;
		}

		return ret;
	}