Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# isUnique

### Description
This repository holds my submission to an assignment for SDEV301 Systems Programming at Green River College. The purpose of this assignment was to review Github forking and provide a light introduction back into algorithms (using Java).

`isUnique` is an algorithm that takes in a given string and returns `true` if all characters in the string are unique and `false` if they are not.

For example:
- "cat" would return `true`, as all characters in "cat" are unique.
- "catch" would return `false`, as the character "c" is occurs twice.

### How to Run the Project
This code can be run as-is with the IntelliJ IDEA IDE from Jetbrains, as long as [Java has been installed](https://www.oracle.com/java/technologies/downloads/) locally.
46 changes: 39 additions & 7 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
/**
* SDEV 301: Systems Programming
*
* @author Kendrick Hang, Tien Han
* @version 1.0
*/

import java.util.ArrayList;

public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
System.out.print("Hello and welcome!");

for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}

//Quick Test
boolean result = isUnique("always");
System.out.println(result);
boolean result2 = isUnique("cat");
System.out.println(result2);
}

//Another way to do this is to use indexOf("a") and lastIndexOf("a")
//If they both return different indexes, then it is not unique
//Another way to do this is the "inchworm" technique, where we look at a character
//And search through the rest of the string to see if it repeats
/**
* isUnique checks if all characters in a given string are unique
* @param word the given string to test
* @return true if string is unique and false if not unique
*/
public static boolean isUnique(String word) {
ArrayList<Character> characters = new ArrayList<>();

for (int i = 0; i < word.length(); i++) {
Character character = word.charAt(i);
if (characters.contains(character)) {
return false;
} else {
characters.add(character);
}
}
return true;
}
}