Time |
S |
Nick |
Message |
00:01 |
|
|
Jantz_ joined ##friendlyjava |
00:37 |
|
|
Jantz joined ##friendlyjava |
01:49 |
|
|
Jantz joined ##friendlyjava |
06:00 |
|
|
nanoz joined ##friendlyjava |
06:00 |
|
nanoz |
aditsu, a single for loop is fine |
06:01 |
|
nanoz |
https://pastebin.com/MM9e3Vjs |
06:44 |
|
nanoz |
english is not my first language |
06:44 |
|
nanoz |
Jantz |
10:43 |
|
|
nanozz joined ##friendlyjava |
11:36 |
|
|
Jantz joined ##friendlyjava |
15:23 |
|
nanozz |
hello aditsu pdurbin |
15:45 |
|
|
Jantz joined ##friendlyjava |
16:15 |
|
aditsu |
hi |
16:18 |
|
aditsu |
nanozz: I looked at your paste, it is very incomplete and extremely inefficient |
16:22 |
|
nanozz |
aditsu, thanks for reviewing |
16:22 |
|
nanozz |
how else i can make it efficent any thoughts |
16:24 |
|
aditsu |
first of all, you don't need a StringBuilder |
16:25 |
|
nanozz |
stringbuilder is used to add/remove and also match the regex for count increase |
16:26 |
|
aditsu |
regex????? |
16:26 |
|
aditsu |
sounds like you're going full Rube Goldberg |
16:26 |
|
nanozz |
yes , build the string match with regex does it start with 1 and end with 1 or you can use startWith and endWith |
16:29 |
|
aditsu |
this is your code: https://www.youtube.com/watch?v=nORRgU8sGdE |
16:34 |
|
nanozz |
:P |
16:35 |
|
nanozz |
please review and let me know :) |
16:35 |
|
aditsu |
let's start with some basic things: how can you check if a substring of your string from i to j starts and ends with 1? |
16:36 |
|
nanozz |
psubstring.startWith == psubstring.endWith == 1 |
16:39 |
|
aditsu |
that's bad (inefficient) for a couple of reasons: 1) creating a substring, 2) startsWith and endsWith work with strings, and there's some overhead to check string lengths, set up a 1-iteration loop, etc |
16:40 |
|
aditsu |
how many characters from your string do you actually need to check? |
16:40 |
|
nanozz |
for example if you take characters as follow |
16:40 |
|
nanozz |
1234 |
16:41 |
|
nanozz |
its substrings are |
16:41 |
|
nanozz |
1,2,3,4,123,12,234,23,34,1234 |
16:41 |
|
aditsu |
why are you talking about that? |
16:42 |
|
nanozz |
an example so we can discuss on this for reference of our talk |
16:43 |
|
aditsu |
well, you have the string, i and j, how many characters do you need to check to find out if the substring from i to j starts and ends with 1? |
16:44 |
|
nanozz |
2 characters |
16:44 |
|
nanozz |
the first and last |
16:45 |
|
aditsu |
good |
16:45 |
|
aditsu |
and what are the positions of those characters in the original string? |
16:46 |
|
nanozz |
0 and n-1 |
16:46 |
|
aditsu |
no, those would be the positions in the substring |
16:50 |
|
nanozz |
:? |
16:51 |
|
aditsu |
well, ok, let's take your example, string is "1234", i=1, j=2 |
16:52 |
|
aditsu |
which characters do you need to check? |
16:53 |
|
nanozz |
ith character and the last character |
16:53 |
|
aditsu |
you're only half right.. |
16:54 |
|
aditsu |
what is the substring in this case? |
16:54 |
|
nanozz |
1234 is the substring sequence |
16:54 |
|
aditsu |
no, "1234" is the original string |
16:54 |
|
nanozz |
yes |
17:30 |
|
|
aditsu joined ##friendlyjava |
18:00 |
|
|
aditsu joined ##friendlyjava |
20:13 |
|
|
Robert_uk joined ##friendlyjava |
20:16 |
|
|
Robert_uk left ##friendlyjava |