Created
September 2, 2018 12:05
-
-
Save kupp1/7cefab3699300977a194bb1e010c0ad4 to your computer and use it in GitHub Desktop.
UniLecs #1. Unique symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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