- 浏览: 186251 次
- 性别:
- 来自: 济南
文章分类
最新评论
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
给定两个非空字符串,里面包含数字和‘ . ’,代表着不同的版本号,让我们判断版本的高低。我们可以用split方法把字符串通过' . '进行分割,得到两个字符串数组,然后依次比较相同位置代表数字的大小。代码如下:
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
给定两个非空字符串,里面包含数字和‘ . ’,代表着不同的版本号,让我们判断版本的高低。我们可以用split方法把字符串通过' . '进行分割,得到两个字符串数组,然后依次比较相同位置代表数字的大小。代码如下:
public class Solution { public int compareVersion(String version1, String version2) { String[] s1 = version1.split("\\."); String[] s2 = version2.split("\\."); int i = 0; for(i = 0; i < s1.length && i < s2.length; i++) { if(Integer.parseInt(s1[i]) != Integer.parseInt(s2[i])) return Integer.parseInt(s1[i]) > Integer.parseInt(s2[i]) ? 1 : -1; } for(; i < s1.length; i++) { if(Integer.parseInt(s1[i]) != 0) return 1; } for(; i < s2.length; i++) { if(Integer.parseInt(s2[i]) != 0) return -1; } return 0; } }
发表评论
-
498. Diagonal Traverse
2019-11-15 13:52 273Given a matrix of M x N eleme ... -
496 Next Greater Element I
2019-11-14 13:50 276You are given two arrays (witho ... -
Word Break II
2016-03-09 03:15 394Given a string s and a dictiona ... -
Insert Interval
2016-03-08 02:11 384Given a set of non-overlapping ... -
Merge Intervals
2016-03-07 05:25 508Given a collection of intervals ... -
Merge k Sorted Lists
2016-03-07 04:03 575Merge k sorted linked lists and ... -
Multiply Strings
2016-03-06 07:27 488Given two numbers represented a ... -
N-Queens II
2016-03-06 03:06 677Follow up for N-Queens problem. ... -
N-Queens
2016-03-06 02:47 481The n-queens puzzle is the prob ... -
First Missing Positive
2016-03-05 03:09 438Given an unsorted integer array ... -
Spiral Matrix
2016-03-04 03:39 589Given a matrix of m x n element ... -
Trapping Rain Water
2016-03-04 02:54 602Given n non-negative integers r ... -
Repeated DNA Sequences
2016-03-03 03:10 434All DNA is composed of a series ... -
Increasing Triplet Subsequence
2016-03-02 02:48 911Given an unsorted array return ... -
Maximum Product of Word Lengths
2016-03-02 01:56 940Given a string array words, fin ... -
LRU Cache
2016-02-29 10:37 610Design and implement a data str ... -
Super Ugly Number
2016-02-29 07:07 706Write a program to find the nth ... -
Longest Increasing Path in a Matrix
2016-02-29 05:56 874Given an integer matrix, find t ... -
Coin Change
2016-02-29 04:39 800You are given coins of differen ... -
Minimum Height Trees
2016-02-29 04:11 739For a undirected graph with tre ...
相关推荐
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++) {...
- “Compare Version Numbers(比较版本号)”则是考查字符串处理和版本控制概念。 - “Copy List with Random Pointer(带有随机指针的复制链表)”涉及到复杂的数据结构操作。 - “Binary Tree Zigzag Level ...
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, ...