Jump to content

Determine if a string has all unique characters: Difference between revisions

m
C++ solution made slightly neater
(Added C++ solution)
m (C++ solution made slightly neater)
Line 678:
size_t len = str.length();
std::cout << "input: \"" << str << "\", length: " << len << '\n';
boolfor unique(size_t i = true0; i < len; ++i)
for (size_t i = 0; i < len && unique; ++i)
{
for (size_t j = i + 1; j < len; ++j)
Line 689 ⟶ 688:
<< "' (hex " << std::hex << static_cast<unsigned int>(str[i])
<< ") occurs at positions " << std::dec << i + 1
<< " and " << j + 1 << ".\n\n";
unique = falsereturn;
break;
}
}
}
std::cout << "String contains no repeated characters.\n\n";
if (unique)
std::cout << "String contains no repeated characters.\n";
std::cout << '\n';
}
 
1,777

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.