小编Aka*_*tra的帖子

How do I check if a string is entirely made of the same substring?

I have to create a function which takes a string, and it should return true or false based on whether the input consists of a repeated character sequence. The length of the given string is always greater than 1 and the character sequence must have at least one repetition.

"aa" // true(entirely contains two strings "a")
"aaa" //true(entirely contains three string "a")
"abcabcabc" //true(entirely containas three strings "abc")

"aba" //false(At least there should be two same substrings and nothing more) …
Run Code Online (Sandbox Code Playgroud)

javascript string algorithm

125
推荐指数
9
解决办法
1万
查看次数

如何从两个已排序数组中的对中获取 K 个最小的乘积?

给出了两个排序数组。我们必须从这些数组的对中找到 K 个最小的乘积。我可以想到 am n logk 解决方案,但即使数组未按排序顺序,该解决方案也有效。我们可以利用这个排序顺序并找到更好的解决方案吗?

我尝试使用大小为 k 的最大堆来获得 m n logk 解决方案。

输入:nums1 = [-2, -1, 0, 1, 2], nums2 = [-3, -1, 2, 4, 5], k = 3 输出:[-10, -8, -6] 解释:-2*5、-2*4、2*-3

algorithm

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

在Python中使用Random.seed(),“ for”和乘法输出30-35之间的随机数

我是编程新手。我分配了一个代码,该代码将输出30到35之间的一个随机数。此代码需要使用random.seed()for语句和乘法。我了解random.seed([x])生成的初始值可以在代码的后续部分中使用。但是,在获得random的值后,我无法弄清楚如何继续:

import random
random.seed(70)
print(random.random()) # This returns a value of 0.909769237923872
Run Code Online (Sandbox Code Playgroud)

如何使用此值生成30到35之间的随机值?

注意:如果没有上述特定说明,我已经能够编写两个可按需运行的代码,因此请不要寻找其他编写代码的方法。

python random python-3.x

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

为类和静态方法配置lru_cache

我试图lru_cache在Python3中使用,以加快我们的Salesforce数据库中的常见查询.下面是相关的代码,它应该a)将不可散列的参数转换为可散列的参数,以及b)为这些对象启用lru缓存.

当我尝试这个代码时,缓存适用于调用没有参数的函数,但它似乎没有用参数缓存函数调用.另外,我不知道如何为装饰函数订购装饰器.

注意,我在这里使用类和静态方法的类,所以我可以覆盖不同子类的getget_all方法Resource.

请解释我做错了什么或者做得更好.

from functools import lru_cache
from functools import wraps

class Resource(object):

    def hash_dict(func):
        """Transform mutable dictionnary
           Into immutable
           Useful to be compatible with cache
        """
        class HDict(dict):
            def __hash__(self):
                return hash(frozenset(self.items()))

        @wraps(func)
        def wrapped(*args, **kwargs):
            args = tuple([HDict(arg) if isinstance(arg, dict) else arg for arg in args])
            kwargs = {}
            for k, v in kwargs.items():
                if isinstance(v, dict):
                    kwargs[k] = HDict(v)
                elif isinstance(v, list):
                    kwargs[k] = tuple(v)
                else:
                    kwargs[k] …
Run Code Online (Sandbox Code Playgroud)

python lru python-3.x

5
推荐指数
2
解决办法
1409
查看次数

如何在 Windows 上重置 MariaDB 密码?

如何在 MariaDB 中重置密码?我使用 Windows 而不是 Linux。谁知道如何重置我的 MySQL MariaDB 密码?我尝试在谷歌上搜索但没有帮助。

mariadb

3
推荐指数
3
解决办法
2万
查看次数

C-编程语言中的复杂声明

我遇到了一个非常复杂的声明,我无法理解:

char ( * ( * f[3]) ()) [5] ;
Run Code Online (Sandbox Code Playgroud)

我想知道如何确定宣布的内容.
另外,由于这个问题是在接受采访时向我询问的,我想知道这些代码是否实际用于软件行业?

如果没有,那么问的目的是什么?

c

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

使用指针访问结构

我已经声明了一个结构"node",它有一个成员变量'm',然后定义了两个变量,如下所示

struct node t, *p;
Run Code Online (Sandbox Code Playgroud)

在稍后的节目给我分配的地址tp:

p = &t;
Run Code Online (Sandbox Code Playgroud)

要访问我需要使用的成员变量p->m.

但我想使用*运算符,但写它*p.m会给出错误.为什么会这样?

c pointers structure

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

标签 统计

algorithm ×2

c ×2

python ×2

python-3.x ×2

javascript ×1

lru ×1

mariadb ×1

pointers ×1

random ×1

string ×1

structure ×1