- 浏览: 173797 次
- 性别:
- 来自: 济南
文章分类
最新评论
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 227Given a matrix of M x N eleme ... -
496 Next Greater Element I
2019-11-14 13:50 228You are given two arrays (witho ... -
Word Break II
2016-03-09 03:15 343Given a string s and a dictiona ... -
Insert Interval
2016-03-08 02:11 335Given a set of non-overlapping ... -
Merge Intervals
2016-03-07 05:25 451Given a collection of intervals ... -
Merge k Sorted Lists
2016-03-07 04:03 513Merge k sorted linked lists and ... -
Multiply Strings
2016-03-06 07:27 431Given two numbers represented a ... -
N-Queens II
2016-03-06 03:06 622Follow up for N-Queens problem. ... -
N-Queens
2016-03-06 02:47 428The n-queens puzzle is the prob ... -
First Missing Positive
2016-03-05 03:09 388Given an unsorted integer array ... -
Spiral Matrix
2016-03-04 03:39 519Given a matrix of m x n element ... -
Trapping Rain Water
2016-03-04 02:54 534Given n non-negative integers r ... -
Repeated DNA Sequences
2016-03-03 03:10 371All DNA is composed of a series ... -
Increasing Triplet Subsequence
2016-03-02 02:48 862Given an unsorted array return ... -
Maximum Product of Word Lengths
2016-03-02 01:56 883Given a string array words, fin ... -
LRU Cache
2016-02-29 10:37 556Design and implement a data str ... -
Super Ugly Number
2016-02-29 07:07 601Write a program to find the nth ... -
Longest Increasing Path in a Matrix
2016-02-29 05:56 765Given an integer matrix, find t ... -
Coin Change
2016-02-29 04:39 736You are given coins of differen ... -
Minimum Height Trees
2016-02-29 04:11 630For a undirected graph with tre ...
相关推荐
version1 和 version2。 如果 version1 > version2 返回 1; 如果 version1 < version2 返回 -1;否则返回 0。 您可以假设版本字符串是非空的并且只包含数字和 . 特点。 这 。 字符不代表小数点,用于分隔数字...
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.你用过哪些...
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 ...
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 ...
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 ...
The compare instruction 138 Examples of using the flag bits 140 Loops 144 The loop instructions 144 A loop example 145 Preventing LOOP catastrophes 145 Duplicating High-Level Conditional Branches 146 ...
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_...
-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, ...
Version 2.3 for MS(R) OS/2 and MS-DOS(R) Operating Systems MICROSOFT CORPORATION Information in this document is subject to change without notice and does not represent a commitment on the part of ...
This will make it easier for the users to compare the theory with the implementation and help them better understand the concept behind each algorithm. Usage In ...
1. Introduction to Zend Framework 1.1. 概述 1.2. 安装 2. Zend_Acl 2.1. 简介 2.1.1. 关于资源(Resource) 2.1.2. 关于角色(Role) 2.1.3. 创建访问控制列表(ACL) ...2.1.5. 定义访问控制 ...