<commit_before>/**
 * Question Link: https://leetcode.com/problems/reverse-vowels-of-a-string/
 * Primary idea: Two pointers, iterate the string and swap two characters each time, 
 * 
 * Note: the input String is case sensitive; thus "aA" should be transferred to "Aa"
 * Time Complexity: O(n), Space Complexity: O(n)
 *
 */

class ReverseVowelsOfAString {
    func reverseVowels(s: String) -> String {
        var left = 0
        var right = s.characters.count - 1
        var chars = [Character](s.characters)
        
        while left < right {
            while left < right && !_isVowel(chars[left]) {
                left += 1
            }
            while left < right && !_isVowel(chars[right]) {
                right -= 1
            }
            guard left < right else {
                break
            }
            _swap(&chars, left, right)
            left += 1
            right -= 1
        }
        
        return String(chars)
    }
    
    private func _isVowel(char: Character) -> Bool {
        var char = String(char).lowercaseString
        if char == "a" || char == "e" || char == "i" || char == "o" || char == "u" {
            return true
        }
        
        return false
    }
    
    private func _swap(inout chars: [Character], _ p: Int, _ q: Int) {
        var temp = chars[p]
        chars[p] = chars[q]
        chars[q] = temp
    }
}<commit_msg>[Array] Change swap function to generic type<commit_after>/**
 * Question Link: https://leetcode.com/problems/reverse-vowels-of-a-string/
 * Primary idea: Two pointers, iterate the string and swap two characters each time, 
 * 
 * Note: the input String is case sensitive; thus "aA" should be transferred to "Aa"
 * Time Complexity: O(n), Space Complexity: O(n)
 *
 */

class ReverseVowelsOfAString {
    func reverseVowels(s: String) -> String {
        var left = 0
        var right = s.characters.count - 1
        var chars = [Character](s.characters)
        
        while left < right {
            while left < right && !_isVowel(chars[left]) {
                left += 1
            }
            while left < right && !_isVowel(chars[right]) {
                right -= 1
            }
            guard left < right else {
                break
            }
            _swap(&chars, left, right)
            left += 1
            right -= 1
        }
        
        return String(chars)
    }
    
    private func _isVowel(char: Character) -> Bool {
        var char = String(char).lowercaseString
        if char == "a" || char == "e" || char == "i" || char == "o" || char == "u" {
            return true
        }
        
        return false
    }
    
    private func _swap<T>(inout chars: Array<T>, _ p: Int, _ q: Int) {
        var temp = chars[p]
        chars[p] = chars[q]
        chars[q] = temp
    }
}
{'fraction_non_alphanumeric': 0.11868597668668315, 'fraction_numerical': 0.0042387848816672555, 'mean_word_length': 1.6053357865685371, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7372530', 'n_tokens_mistral': 884, 'n_tokens_neox': 837, 'n_words': 248}