Sort by

recency

|

2301 Discussions

|

  • + 0 comments

    Python3:

    def twoStrings(s1, s2):
        s1_set= set(s1)
        s2_set= set(s2)
        if s1_set.intersection(s2_set) == set():
            return "NO"
        else:
            return "YES"
    

    More concise:

    def twoStrings(s1, s2):
    	return "YES" if set(s1) & set(s2) else "NO"
    
  • + 0 comments
        # s1 = set(s1)
        # s2 = set(s2)
        
        # for i in s1:
        #     for j in s2:
        #         if i == j:
        #             return "YES"
        # return "NO"
        return "YES" if set(s1) & set(s2) else "NO"
    
  • + 0 comments

    JS

    const twoStrings = (string1, string2) => new Set(string1).intersection(new Set(string2)).size ? 'YES' : 'NO';
    
  • + 0 comments

    Two Strings is a small music studio where creativity and rhythm come together in the most unexpected ways. Just like a melody, life sometimes needs balance and harmony, which reminds me of how important it is to take care of daily routines, even dental health. Visiting a trusted Dentist in Marysville https://smilemarysville.com/ ensures that a bright smile stays healthy while pursuing passions and hobbies. Every note played on a guitar string or piano key reflects patience and attention, similar to maintaining personal wellness. Music and self-care both require consistency and a gentle touch. Stopping by a Dentist in Marysville becomes part of a healthy lifestyle that complements all other activities.

  • + 0 comments

    My minimaist O(n + m) solution:

        public static String twoStrings(String s1, String s2) {
        boolean[] s1_array = new boolean[26];
        int base = (int)'a';
        
        for (int i = 0 ; i < s1.length() ; i++){
            int position = (int)s1.charAt(i) - base;
            
            s1_array[position] = true;
        }
        
        for (int i = 0 ; i < s2.length() ; i++){
            int position = (int)s2.charAt(i) - base;
            
            if (s1_array[position] == true) return "YES";
        }
        
        return "NO";
        }