Skip to content

undefined: while #22

Open
Open
@Chanyon

Description

@Chanyon
string S = "abcdefx";
string T = "def";
int myIndex(string S,string T,int pos) {
  int i = pos;
  int j = 0;
  byte[] s = toByteArray(S);
  byte[] t = toByteArray(T);

  int slen = len(s);
  int tlen = len(t);
  while(i <= slen && j <= tlen) { //undefined: while
  // for(i <= slen && j <= tlen) {
    if (s[i] == s[j]) {
      i += 1;
      j += 1;
    }else{
      i = i - j + 1;
      j = 0;
    }
  }
  if (j == tlen) {
    return i - tlen;
  } else {
    return 0;
  }
}

int res = myIndex(S,T,0);
println(res);

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions