-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday12_2.java
More file actions
71 lines (58 loc) · 1.43 KB
/
day12_2.java
File metadata and controls
71 lines (58 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// User function Template for Java
class Solution {
public boolean isValid(String s) {
// Write your code here
int n = s.length();
String[] num = s.split("[.]");
boolean ans = true;
int dot =0;
for(int i=0; i<s.length(); i++)
{
if(s.charAt(i)=='.')
{
dot++;
}
}
if(dot!=3)
{
return false;
}
if(num.length!=4)
{
return false;
}
for(int i=0; i<num.length; i++)
{
try
{
int k = Integer.parseInt(num[i]);
}
catch(NumberFormatException e)
{
return false;
}
int k = Integer.parseInt(num[i]);
if(k<0 || k>255)
{
return false;
}
if(num[i].length()>3)
{
return false;
}
if(num[i].equals("00"))
{
return false;
}
if(num[i].equals("000"))
{
return false;
}
if( num[i].length()>1 && (num[i].charAt(0)=='0'))
{
return false;
}
}
return ans;
}
}