-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ht Diana #3
base: master
Are you sure you want to change the base?
ht Diana #3
Conversation
String substring = shortstr.substring(0); | ||
return substring; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's quite uncommon way to solve this task.
Actually, there is no need for StringBuilder here - you can just use substring
method of String
.
Also, you can move length check to null-check, so that you'll check string for null and for length<2
and just return s
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it means like this ?6cac7fc
String closetag = "</" + tag + ">"; | ||
String html = opentag + text + closetag; | ||
|
||
return html; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's OK, but IMO, it's better to solve this task with StringBuilder
and the best solution will be using String.format()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed with string format e1d526d
return html; | ||
|
||
return String.format("%s", "<" + tag + ">" | ||
+ text + "</" + tag + ">"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are almost done.
Now, there is no need to use only one %s
in format.
Also, you can combine format with any symbols, so that it should look like: <%s>%s...
if (i > 0 && i >= s.length()) { | ||
i = i - s.length(); | ||
} | ||
return String.valueOf(s.charAt(i)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your implementation pass all tests, but you've used lots of unnecessary operations and it'll be quite slow (due to additional usage of Math
and StringBuilder
.
Try to solve this task from Math point of view - you just need to calculate char index properly and this could be done using %
operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i didn't have any idea. what do you mean about use % operator ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%
- is modulus operator in Java.
For example for positive index, result index on which you can get needed char could be calculated in following way:
int index %=s.length()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, interesting. thx
|
||
if (lengthA >= 1 && lengthB >= 1) { | ||
return a[0] == b[0] || a[a.length - 1] == b[b.length - 1] || a[0] == b[b.length - 1] || a[a.length - 1] == b[0]; | ||
} | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again. It do pass all tests, but it's again to complicated.
Why do you need this if
clause ? Also there is no need for lengthA
and lengthB
vars (or you should reuse them everywhere).
By the task description: you'll 100% have arrays with length>=1.
return false; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- you don't need
if
clause, as result of your expression isboolean
- you can just return it. - you should cover one more case - last
a
is equal to lastb
.
for (int i = arr.length - 1; i >= 0; --i) { | ||
reverseArr[i] = arr[n]; | ||
n++; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can create more complex for
condition:
for (int i = arr.length - 1, n=0; i >= 0 && n<arr.length; i--, n++) {
reverseArr[i] = arr[n];
}
But, actually, this task could be solved with only one index variable.
} | ||
int n = 0; | ||
for (int i = arr.length - 1; i >= 0; --i) | ||
if (arr[i] % 2 == 0 || arr[i] == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for you additional condition arr[i]==0
cause even when arr[i]
will be 0
- 0%2 ==0
will return true.
@dianasinenchenko Please remove wrong |
@dianasinenchenko What about task 9 and task 10 ? |
@xSAVIKx i try writing correct pattern for task 9. will be today |
@dianasinenchenko What exact problems do you have ? If you need any assistance - it's better to ask questions via Gitter |
StringBuilder surl = new StringBuilder(); | ||
if (murl.find()){ | ||
surl.append(murl.group()).append("\n"); | ||
return new String[]{surl.toString()}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to avoid such naming.
Characters are free of charge now and you can easily create names with any length.
Also, follow lowerCamelCase for variables names.
Following names would be better:
url -> regexp
purl -> urlPattern
murl -> urlMatcher
surl -> result
.
Also, you need to provide String[3]
array and with current implementation you'll supply String[1]
array, as surl.toString()
will create one String
object.
|
||
String url =" ( (?<=\\:\\/\\/) [\\w] +.) ? ((?<= \\/\\/) [\\w\\d.-_] +.) ((?<=\\: ) [\\d] ) "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure, that your regexp is not correct.
Schema could contain only [a-zA-Z0-9].
Host could contain [a-zA-Z0-9-_.]
Port could have more than 1 number
No description provided.