文件: root - text - article - 2020 - 02 - compare-version-numbers.txt
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 587 次阅读, 24144 次搜索 | 192 个单词
| 浏览 | 博客存档
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 587 次阅读, 24144 次搜索 | 192 个单词
| 浏览 | 博客存档
Hi, here's your problem today. This problem was recently asked by Amazon:
Version numbers are strings that are used to identify unique states of software products. A version number is in the format a.b.c.d. and so on where a, b, etc. are numeric strings separated by dots. These generally represent a hierarchy from major to minor changes. Given two version numbers version1 and version2, conclude which is the latest version number. Your code should do the following:
If version1 > version2 return 1.
If version1 < version2 return -1.
Otherwise return 0.
Note that the numeric strings such as a, b, c, d, etc. may have leading zeroes, and that the version strings do not start or end with dots. Unspecified level revision numbers default to 0.
Example:
Input:
version1 = "1.0.33"
version2 = "1.0.27"
Output: 1
#version1 > version2
Input:
version1 = "0.1"
version2 = "1.1"
Output: -1
#version1 < version2
Input:
version1 = "1.01"
version2 = "1.001"
Output: 0
#ignore leading zeroes, 01 and 001 represent the same number.
Input:
version1 = "1.0"
version2 = "1.0.0"
Output: 0
#version1 does not have a 3rd level revision number, which
defaults to "0"
Here's a starting point
标签: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | 英文 | 主页 | 类别: 计算机科学 | 587 次阅读, 24144 次搜索 | 192 个单词 Version numbers are strings that are used to identify unique states of software products. A version number is in the format a.b.c.d. and so on where a, b, etc. are numeric strings separated by dots. These generally represent a hierarchy from major to minor changes. Given two version numbers version1 and version2, conclude which is the latest version number. Your code should do the following:
If version1 > version2 return 1.
If version1 < version2 return -1.
Otherwise return 0.
Note that the numeric strings such as a, b, c, d, etc. may have leading zeroes, and that the version strings do not start or end with dots. Unspecified level revision numbers default to 0.
Example:
Input:
version1 = "1.0.33"
version2 = "1.0.27"
Output: 1
#version1 > version2
Input:
version1 = "0.1"
version2 = "1.1"
Output: -1
#version1 < version2
Input:
version1 = "1.01"
version2 = "1.001"
Output: 0
#ignore leading zeroes, 01 and 001 represent the same number.
Input:
version1 = "1.0"
version2 = "1.0.0"
Output: 0
#version1 does not have a 3rd level revision number, which
defaults to "0"
Here's a starting point
class Solution:
def compareVersion(self, version1, version2):
# Fill this in.
version1 = "1.0.1"
version2 = "1"
print(Solution().compareVersion(version1, version2))
# 1
猜您喜欢...
- [Daily Problem] Validate Balanced Parentheses
- Algorithm Interview: Maximum Path Sum in Binary Tree
- Algorithm Interview: Longest Consecutive Sequence
- New Vulnerabilities (CVE-2016-4581) have been detected in CentOS/RHEL/CloudLinux 7
- Daily Interview Puzzle: Ways to Traverse a Grid
- Daily Interview Problem: Find the k-th Largest Element in a List
- [Daily Problem] Witness of The Tall People
- Daily Interview Problem: Given two arrays, write a function to compute their intersection.
- Daily Interview Problem: Reverse Words in a String
- Linode Support Ticket 10029540 - Other - Important Notice Regarding Ubuntu 17.10 Image
©2006~2024 牛排过熟 - 0.0079 秒 - 2689.934 KB/s - 37 在线 内存: 495.81 KB
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
牛排怎么做才好吃? | <meta name="机器人" content="索引, 跟踪">
18:54:01 up 13 days, 18:33, 2 users, load average: 0.98, 0.86, 0.73 - 服务器 PHP 版本号: 7.4.33
评论 (0)
读写完全 - 一般 - 最小 - 表格 - 所有评论 - 统计
当前页暂时没有评论。