/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param n int整型 * @param m int整型 * @return int整型 */ typedef struct ListNode ListNode; ListNode* buynode(int x) { ListNode* node = (ListNode*)malloc(sizeof(ListNode)); if(node == NULL) { exit(1); } node->val = x; node->next = NULL; return node; } ListNode* createcic(int n) { //创建第一个节点 ListNode* phead = buynode(1); ListNode* ptail = phead; for(int i = 2;i <= n;i++) { ptail->next = buynode(i); ptail = ptail->next; } ptail->next = phead; return ptail; } int ysf(int n, int m ) { //1.创建带环链表 ListNode* prev = createcic(n); //2.遍历链表,删除节点 ListNode* pcur = prev->next; int count = 1; while(pcur->next != pcur) { if(count == m) { prev->next = pcur->next; free(pcur); pcur = prev->next; count = 1; } else { prev = pcur; pcur = pcur->next; count++; } } return pcur->val; }