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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ You can contribute to any open source project hosted on Github.com and contribut
| Two Sum | :white_check_mark: | :white_check_mark: | | | | | |
| Variations of LIS | | | | | | | |
| Word Wrap Problem | | | | | | | |
| Strobogrammatic number | | :white_check_mark: | | | | | |

## Data Structures Implementations.

Expand Down
32 changes: 32 additions & 0 deletions others/cpp/strobogrammatic.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Scanner;
class strobogrammatic {
public static boolean isStrobogrammatic(char[] digits) {
int left = 0;
int right = digits.length - 1;

while (left <= right) {
char c1 = digits[left];
char c2 = digits[right];
if (c1 == '0' && c2 == '0' || c1 == '1' && c2 == '1' || c1 == '8' && c2 == '8' || c1 == '6' && c2 == '9' || c1 == '9' && c2 == '6') {
left++;
right--;
} else {
return false;
}
}

return true;
}

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
char[] digits = String.valueOf(num).toCharArray();

if (isStrobogrammatic(digits)) {
System.out.println("Strobogrammatic");
} else {
System.out.println("Not Strobogrammatic");
}
}
}