algorithm - 如何在不使用任何额外内存的情况下从 unicode 字符链表中消除重复项

标签 algorithm linked-list

“在 unicode 字符链表中找到一个重复出现的元素。如果发现 unicode 字符有重复项,则只需删除该重复节点并调整列表。约束是不使用任何额外的内存。”

我的回答:
假设 unicode char 不包含代理项对 char 因为我正在使用 c#

我不知道你怎么能找到重复的字符,除非你在遍历列表时知道先前节点的值,并且要维护先前的值你将需要额外的内存(哈希表)。

伙计们,你能想出解决这个问题的办法吗?这是其中一个网站上的面试问题。也有可能在 O(n) 时间内解决这个问题吗?
这是我的实现。您能否就此提供反馈,以便我改进它?

public static void RemoveDup(Node head)
        {
            Node current1 = head;
            Node current2;



            while (current1 != null)
            {
                current2 = current1;
                while (current2 != null)
                {
                    if (current2.Next!=null && current1.Data == current2.Next.Data)
                    {
                        Node temp = current2.Next.Next;
                        current2.Next = temp;
                        current2=current1;
                        continue;                        
                    }

                    current2 = current2.Next;
                    if (current2 == null)
                        break;

                }

                current1 = current1.Next;
                if (current1 == null)
                    break;
            }


        }

最佳答案

对于列表中的每个元素,在列表中搜索该元素并从该元素的位置开始删除它,直到没有元素为止。

我会将实现和其他选择留给您。

关于algorithm - 如何在不使用任何额外内存的情况下从 unicode 字符链表中消除重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1178038/

相关文章:

algorithm - 我无法真正理解强连通分量算法是如何工作的

C:结构化数据类型 - 链表

c - 根据匹配数据删除节点

c - 使用链接列表时 While 循环失败

algorithm - 检测调度程序时间轴上的冲突(算法)

algorithm - 最佳优先搜索 TSP 在矩形上失败而在圆形上获胜,为什么?

c# - 如何计算集合中值的百分位数或排名?

python - python中字符串的所有可能长度k组合

c++ - 这个迭代器会出什么问题?

c - 在一个函数create_new_node中连接一个节点的所有链接可以吗?