Compare two version numbers version1 and version2.
If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.
You may assume that the version strings are non-empty and contain only digits and the .
character.
The .
character does not represent a decimal point and is used to separate number sequences.
For instance, 2.5
is not "two and a half" or "half way to version three", it is the fifth second-level revision of the second first-level revision.
Here is an example of version numbers ordering:
0.1 < 1.1 < 1.2 < 13.37
public class Solution { public int compareVersion(String version1, String version2) { int len1 = version1.length(); int len2 = version2.length(); int i = 0; int j = 0; int a = 0; int b = 0; while (i < len1 || j < len2) { while (i < len1 && version1.charAt(i) != '.') { a = a * 10 + (version1.charAt(i) - '0'); i++; } while (j < len2 && version2.charAt(j) != '.') { b = b * 10 + (version2.charAt(j) - '0'); j++; } if (a > b) { return 1; } else if (a < b) { return -1; } i++; j++; a = b = 0; } return 0; } }
相关推荐
version1 和 version2。 如果 version1 > version2 返回 1; 如果 version1 < version2 返回 -1;否则返回 0。 您可以假设版本字符串是非空的并且只包含数字和 . 特点。 这 。 字符不代表小数点,用于分隔数字...
javascript js_leetcode题解之165-compare-version-numbers.js
python python_leetcode题解之165_Compare_Version_Numbers.py
public int compareVersion(String version1, String version2) { String[] nums1 = version1.split("\\."); String[] nums2 = version2.split("\\."); for (int i = 0; i (nums1.length, nums2.length); i++) {...
201 | [Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range/) | [C++](./C++/bitwise-and-of-numbers-range.cpp) [Python](./Python/bitwise-and-of-numbers-range.py) | _...
Compare Version Numbers 排列组合 链表 topk大数据 [Github]: Java面试指南 BAT String Reverse 进程 线程 程序 协程 Java 总结 云粒智慧 1.你的项目中你感觉有哪些缺点 2.你的项目的架构图是什么 3.你用过哪些...
Optional<Integer> max = numbers.stream().max(Integer::compare); Optional<Integer> min = numbers.stream().min(Integer::compare); Integer sum = numbers.stream().reduce(0, Integer::sum); Double ...
Horizontal Error Bars - Version 6.0 gives developers the ability to add error bars to bar charts, which offers additional statistical information regarding the data on the chart for more in depth ...
--numeric-owner always use numbers for user/group names -p, --same-permissions extract all protection information --preserve-permissions same as -p -s, --same-order sort names to extract to match ...
1. **Step 1**: Select the two files or directories you want to compare. 2. **Step 2**: Run the DIFF tool. 3. **Step 3**: Review the differences highlighted. 4. **Step 4**: Resolve any discrepancies as...
you run the demo.bat program, and you can compare corresponding files to see that they are the same. All you have to do is run "demo.bat" in order to both train and test the batchnet artificial ...
- **Objective:** Compare two dictionaries and find differences. - **Key Concepts:** - Iterating over dictionary keys. - Comparing values and handling missing keys. 17. **How Many Different ...
In this version I have done away with the b+tree and hash index in favor of my own MGIndex structure which for all intents and purposes is superior and the performance numbers speak for themselves....
Determining Extensions and Implementation Version Summary References Exercises Appendix A. Command-Line Environments Logging in Logging out Security Text editing Uploading files ...
This program is used internally to test/validate/compare different implementations (e.g., Reference, Optimized, Assembly). skein_block_x64.asm This is the 64-bit assembly language version of skein_...
4. **Compare Demo**: 这可能是一个演示或示例,用于展示如何对比测试结果,对于验证和调试自动化测试过程非常有用。 5. **Nude Shell**: 与"Nude Shell Version 2.0"相似,可能是用于执行命令的界面,但可能不包含...
-seed value seed a new sequence of pseudo-random numbers -size geometry width and height of image -stretch type render text with this font stretch -stroke color graphic primitive stroke color -...
2. Basic Version-Control Concepts 2.1. 版本库 2.2. 版本模型 2.2.1. 文件共享的问题 2.2.2. 锁定-修改-解锁 方案 2.2.3. 复制-修改-合并 方案 2.2.4. Subversion 怎么做? 2.3. Subversion 实战 2.3.1. ...
Higher numbers compress better but run slower and use more memory. -3 is the default, and gives a reasonable tradeoff. Recommended options are: -0 to -2 for fast (2X over -3) but poor compression, ...