leetcode刷题记--ReverseInteger-续

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 class Solution: def reverse(self, x): # 取出符号位 sign = -1 if x<0 else 1 # 把x化为正数 x*=sign rev = 0 while not x==0: rev*=10 rev += x%10 x = x//10 if not -2**31<=rev<=2**31-1: return 0 return rev*sign 上面代码是在lee

leetcode刷题记--ReverseInteger

Given a 32-bit signed integer, reverse digits of an integer Example 1: 1 2 Input: 123 Output: 321 Example 2: 1 2 Input: -123 Output: -321 Example 3: 1 2 Input: 120 Output: 21 Note: Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−2**31, 2**31 − 1]. For the purpose of this problem,

leetcode刷题记--TwoSum

Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the same element twice. Example: 1 2 3 4 Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1]. My answer:

彩票下注程序

问题背景 Java实验课作业 问题描述 实现一个彩票游戏,要求允许用户输入下注的注数,每注七个不重复的号码并在1~35之间选取,最后输出要按照顺序