Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, then you must output 3→2→1→6→5→4; if K=4, you must output 4→3→2→1→5→6.
Photoinduced Bending Behaviour of Cross-linked Liquid Crystalline Polymers with High Cross-linking Densities,蒋臻,吕久安,In this paper, highly crosslinked liquid-crystalline polymer (CLCP) films with a longer spacer and different locations and concentrati
方法1
思路:将链表中的元素都保存list中,并判断这个list和反转后的list,是否相同,如果相同,则回文;否则,则不回文。
性能分析:时间复杂度为O(n);空间复杂度为O(n) [因为用到了extra space list]
方法2
思路:将链表等分为两部分,判断前半部分和后半部分的逆序是否相等,如果相等,则回文,否则不回文。
性能分析:时间复杂度为O(n);空间复杂度为O(1)[no extra space
# Definition for singly-li