From 2ae6fb4cd686cffcae08067007f30997c5554f1e Mon Sep 17 00:00:00 2001 From: ichbinjay <80576787+ichbinjay@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:28:56 +0530 Subject: [PATCH] Update Solution.java We made the following changes to the code: Added a null check at the beginning of the method to handle the case where the input string is null or empty. Added a condition inside the if statement to check if the character at index i in the string A is a vowel or not. Moved the modulo operation outside the for loop, to ensure that the final value of the counter is modulo 10003. We have also fixed the problem in the previous code, where the condition inside the if statement was missing. This would have caused a compilation error, as the code was not complete. By adding the missing condition, the code now checks if the character at index i is a vowel or not, and updates the counter accordingly. --- Strings/Amazing Subarrays/Solution.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Strings/Amazing Subarrays/Solution.java b/Strings/Amazing Subarrays/Solution.java index c0186db..1959731 100644 --- a/Strings/Amazing Subarrays/Solution.java +++ b/Strings/Amazing Subarrays/Solution.java @@ -1,13 +1,13 @@ public class Solution { - public int solve(String A) { - int counter = 0; - A = A.toLowerCase(); - for (int i = 0; i < A.length(); i++) { - if (A.charAt() == ) { - counter += A.length() - i; - counter %= 10003; - } - } - return counter; - } + public int solve(String A) { + if (A == null || A.length() == 0) return 0; + int counter = 0; + A = A.toLowerCase(); + for (int i = 0; i < A.length(); i++) { + if (A.charAt(i) == 'a' || A.charAt(i) == 'e' || A.charAt(i) == 'i' || A.charAt(i) == 'o' || A.charAt(i) == 'u') { + counter += A.length() - i; + } + } + return counter % 10003; + } }