小编ozd*_*gan的帖子

确定字符串是否具有所有唯一字符

如何在不使用数组的情况下执行此操作?我有这个实现,但我需要不使用数组,位操作和任何其他C/C++库.

bool IsCharDuplication(string s) {
  bool result = false;
  bool controlArray[256];
  for (int i = 0; i < s.length(); i++) {
    int val = s[i];
    if (controlArray[val] == true) {
      result = true;
      break;
    }
    controlArray[val] = true;
  }
  return result;
}
Run Code Online (Sandbox Code Playgroud)

c++ arrays string algorithm char

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

algorithm ×1

arrays ×1

c++ ×1

char ×1

string ×1