Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
description added and also link to the algorithm review
  • Loading branch information
vakhokoto committed Jul 22, 2020
commit a983a15b62c0f98b626c6ebc194ecbf950aa369a
14 changes: 9 additions & 5 deletions Strings/ZFunction.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
// Initialisation of strings algorithm Z function
// detailed review and proper examples can be seen on the link bewlow
//
// Link of algorithm review: https://www.geeksforgeeks.org/z-algorithm-linear-time-pattern-searching-algorithm/
package Strings;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kindly add a description of your code as this repository is for learning purpose

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any standards that this repo follows? If so can you show me an example of the description so I meet that standards.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @deadshotsb I have added description and link of the algorithm review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the inconvenience, @vakhokoto, kindly give a desciption instead of providing links, you can give an example case if needed.


public class ZFunction {
private String s;
private String string;

public ZFunction(String s){
this.s = s;
public ZFunction(String string){
this.string = string;
}

public int[] getArray(){
int length = s.length();
int length = string.length();
int[] z = new int[length];
int l = 0, r = 0;
for (int i=0; i<length; i++){
if (i > l && i <= r){
z[i] = Math.min(z[i - l], r - i + 1);
}
while (i + z[i] < length && s.charAt(z[i]) == s.charAt(i + z[i])){
while (i + z[i] < length && string.charAt(z[i]) == string.charAt(i + z[i])){
z[i]++;
}
if (i + z[i] > r){
Expand Down