More Than Codes

怕什么真理无穷,进一步有进一步的欢喜。


  • 首页

  • 归档

  • 搜索

【LeetCode刷题记录】7.Reverse Integer

发表于 2017-04-25
字数统计: 375 字 | 阅读时长 ≈ 2 分钟

Description:

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

Have you thought about this?
Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!

If the integer’s last digit is 0, what should the output be? ie, cases such as 10, 100.

Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, then the reverse of 1000000003 overflows. How should you handle such cases?

For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

Note:
The input is assumed to be a 32-bit signed integer. Your function should return 0 when the reversed integer overflows.

解体思路:这道题目比较简单,难点在于溢出的判断与处理。

阅读全文 »

【LeetCode刷题记录】1.Two Sum解法与Hashmap的应用

发表于 2017-04-24
字数统计: 671 字 | 阅读时长 ≈ 3 分钟

Description:

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:

Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 = 9,return [0, 1].

阅读全文 »
123
金成能

金成能

22 日志
GitHub E-Mail
© 2020 金成能
由 Hexo 强力驱动
|
主题 — NexT.Muse v5.1.3