From 5c47b118d0bda2b4b517a826cba34973d7050cd2 Mon Sep 17 00:00:00 2001 From: Rajkanwar Singh Date: Mon, 2 Oct 2023 22:09:45 +0530 Subject: [PATCH 1/2] Update README.md Added Strobogrammatic Number --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cd92c21..6969b17 100644 --- a/README.md +++ b/README.md @@ -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. From a75db4736b7999ad9254d633f4659aa5c4557dbb Mon Sep 17 00:00:00 2001 From: Rajkanwar Singh Date: Mon, 2 Oct 2023 22:11:44 +0530 Subject: [PATCH 2/2] Create strobogrammatic.java --- others/cpp/strobogrammatic.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 others/cpp/strobogrammatic.java diff --git a/others/cpp/strobogrammatic.java b/others/cpp/strobogrammatic.java new file mode 100644 index 0000000..8477332 --- /dev/null +++ b/others/cpp/strobogrammatic.java @@ -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"); + } + } +}