Skip to content

Latest commit

 

History

History
56 lines (46 loc) · 1.26 KB

Question_1119.md

File metadata and controls

56 lines (46 loc) · 1.26 KB

LeetCode Records - Question 1119 Remove Vowels from a String

Attempt 1: Use replaceAll()

class Solution {
    public String removeVowels(String s) {
        return s.replaceAll("[aeiou]+", "");
    }
}
  • Runtime: 1 ms (Beats: 65.59%)
  • Memory: 41.30 MB (Beats: 51.77%)

Attempt 2: Use an if statement (AND)

class Solution {
    public String removeVowels(String s) {
        StringBuilder stringBuilder = new StringBuilder();

        for (char ch : s.toCharArray()) {
            if (ch != 'a' && ch != 'e' && ch != 'i' && ch != 'o' && ch != 'u') {
                stringBuilder.append(ch);
            }
        }

        return stringBuilder.toString();
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 40.81 MB (Beats: 97.43%)

Attempt 3: Use an if statement (OR)

class Solution {
    public String removeVowels(String s) {
        StringBuilder stringBuilder = new StringBuilder();

        for (char ch : s.toCharArray()) {
            if (!(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')) {
                stringBuilder.append(ch);
            }
        }

        return stringBuilder.toString();
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 41.32 MB (Beats: 51.77%)