Skip to content

Instantly share code, notes, and snippets.

@kupp1
Created September 2, 2018 12:05
Show Gist options
  • Select an option

  • Save kupp1/7cefab3699300977a194bb1e010c0ad4 to your computer and use it in GitHub Desktop.

Select an option

Save kupp1/7cefab3699300977a194bb1e010c0ad4 to your computer and use it in GitHub Desktop.
UniLecs #1. Unique symbols
def check_unique_symbols(string: str):
"""
Check if in string unique symbol repeats.
"""
symbols = []
for symbol in string:
if symbol in symbols:
return False
else:
symbols.append(symbol)
return True
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool checkUniqueSymbols(char* string) {
for (int i = 0; i < strlen(string); i++) {
for (int j = i + 1; j < strlen(string); j++) {
if (string[i] == string[j]) {
return false;
}
}
}
return true;
}
int main(void) {
char string[100];
scanf("%[^\n]s", string);
printf("%d\n", checkUniqueSymbols(string));
return 0;
}
package main
import "fmt"
func runeInSlice(a rune, list []rune) bool {
// Check if rune in rune array
for _, b := range list {
if b == a {
return true
}
}
return false
}
func checkUniqueSymbols(str string) bool {
// Check if in string unique symbol repeats.
var runes []rune
for _, char := range str {
if runeInSlice(char, runes) {
return false
} else {
runes = append(runes, char)
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment