C# Code


  • 0
    P
      public IList<IList<int>> PalindromePairs(string[] words)
            {
                IList<IList<int>> tobe = new List<IList<int>>();
                if (words == null || words.Length == 0)
                    return tobe;
    
                for (int i = 0; i < words.Length; i++)
                {
                    for(int j = 0; j < words.Length; j++)
                    {
                        List<int> within = new List<int>();
    
                        if (i != j)
                            if (isPalin(words[i] + words[j]))
                            {
                                within.Add(i);
                                within.Add(j);
                            }
                        if (within.Count > 0)
                            tobe.Add(within);
                    }
                }
                return tobe;
            }
    
            public bool isPalin(string test)
            {
                int l = 0, r = test.Length - 1;
                while (l <= r)
                {
                    if (test[l] == test[r])
                    {
                        l++; r--;
                    }
                    else
                        return false;
                }
    
                return true;
            }

  • 0

    What's the time complexity of this solution?


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.