Example of O(n!)?

后端 未结 16 2476
渐次进展
渐次进展 2020-11-30 22:20

What is an example (in code) of a O(n!) function? It should take appropriate number of operations to run in reference to n; that is, I\'m asking a

16条回答
  •  余生分开走
    2020-11-30 22:48

    In C#

    Wouldn't this be O(N!) in space complexity? because, string in C# is immutable.

    string reverseString(string orgString) {
        string reversedString = String.Empty;
    
        for (int i = 0; i < orgString.Length; i++) {
            reversedString += orgString[i];
        }
    
        return reversedString;
    }
    

提交回复
热议问题