小编mon*_*ter的帖子

为什么内联函数的效率低于内置函数?

我正在InterviewBit上尝试关于数组的问题.在这个问题中,我创建了一个内联函数,返回整数的绝对值.但有人告诉我,我的算法在提交时效率不高.但当我改为使用abs()C++库时,它给出了正确的答案判决.

这是我的功能得到了一个低效的判决 -

inline int abs(int x){return x>0 ? x : -x;}

int Solution::coverPoints(vector<int> &X, vector<int> &Y) {
    int l = X.size();
    int i = 0;
    int ans = 0;
    while (i<l-1){
        ans = ans + max(abs(X[i]-X[i+1]), abs(Y[i]-Y[i+1]));
        i++;
    }
    return ans;
}
Run Code Online (Sandbox Code Playgroud)

这是得到正确答案的那个-

int Solution::coverPoints(vector<int> &X, vector<int> &Y) {
    int l = X.size();
    int i = 0;
    int ans = 0;
    while (i<l-1){
        ans = ans + max(abs(X[i]-X[i+1]), abs(Y[i]-Y[i+1])); …
Run Code Online (Sandbox Code Playgroud)

c++ arrays

22
推荐指数
3
解决办法
1701
查看次数

尝试更改 mysql 密码时出错

我忘记了 mysql 的密码,所以我尝试使用以下步骤更改它 -

1)停止Mysql服务器

2)使用以下命令以安全模式启动服务器sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables

3)使用打开mysql命令行sudo /usr/local/mysql/bin/mysql -u root

4)使用更新密码UPDATE mysql.user SET authentication_string=PASSWORD('NewPassword') WHERE User='root';

但在这一步我收到以下错误消息 -

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('NewPassword') WHERE User='root'' at line 1
Run Code Online (Sandbox Code Playgroud)

有人可以告诉如何解决这个错误吗?

mysql passwords

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

静态方法不能直接调用非静态方法

根据javatpoint 中写的限制,静态方法不能直接调用非静态方法。“直接”究竟是什么意思,为什么我不能这样做?是的,我可以通过哪些间接方式做到这一点?

java static

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

标签 统计

arrays ×1

c++ ×1

java ×1

mysql ×1

passwords ×1

static ×1