小编Nic*_*ter的帖子

如何在 Kotlin 中乘以列表

如果我有一个清单:

val a: mutableListOf<Int> = (1,2,3,4) 我希望有一个新的列表b(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)

在 python 中,你可以只拥有 a * 3

在 Kotlin 中如何实现这一点?

kotlin

7
推荐指数
1
解决办法
157
查看次数

链表插入和反向输出

我有这段代码,我正在处理添加一些字符串 aa 链接列表以反转列表。但我收到段错误错误。

segmentation fault: 11 是我在编译器上看到的。

可能会涉及内存分配问题,但目前这并不重要。

还有一个警告字符常量对于它的类型来说太长了。我不确定这意味着什么。

我怎么解决这个问题?

#include <stdio.h> 
#include <stdlib.h> 

struct Node { 
    char *data[100]; 
    struct Node *next; 
}; 

static void reverse(struct Node **head_ref) { 
    struct Node *prev = NULL; 
    struct Node *current = *head_ref; 
    struct Node *next = NULL; 
    while (current != NULL) { 
        // Store next 
        next = current->next; 

        // Reverse current node's pointer 
        current->next = prev; 

        // Move pointers one position ahead. 
        prev = current; 
        current = next; 
    } 
    *head_ref = prev; 
} …
Run Code Online (Sandbox Code Playgroud)

c malloc linked-list

1
推荐指数
1
解决办法
49
查看次数

在列表中查找下一个最接近的数字

我有一个清单:

lst = [100, 210, 330, 460, 600, 750, 910, 1080, 1260]
Run Code Online (Sandbox Code Playgroud)

和一个给定的数字 470

我想找到它的两个最接近的数字之间的间隔的下一个上限......这会给出,600因为它是下一个最接近的数字。

如果是670我会得到750

我有lst[min(range(len(lst)), key = lambda i: abs(lst[i]-K))]哪个给出壁橱编号,无论它是否是上限。

python algorithm python-3.x

-1
推荐指数
1
解决办法
41
查看次数

标签 统计

algorithm ×1

c ×1

kotlin ×1

linked-list ×1

malloc ×1

python ×1

python-3.x ×1