好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

算法训练营

download:算法训练营

Q:课程是用什么语言教学的? 算法训练营是用 Java 和 Python 教学,不过课程重要的是思路的讲解,不要求必须掌握 Java 和 Python,以往学员中有 C++、PHP、甚至是前端开发工程师,也完全可以学习。 Q:每天需要投入多少时间来学习? 每周需要投入 8-12 小时来观看课程视频,并完成当周作业。

哪些人适合报名算法训练营?

近期有大厂跳槽计划,需快速掌握算法 想进入大数据等热门领域,算法是短板 多次自学算法,但是始终坚持不下去 明白算法知识原理,做题却找不到最优解 无数次下定决心刷题,却不到 3 天就放弃 清楚算法的重要性,但找不到学习方法 函數操作 對條件字段做函數操作走不了索引。

select * from t1 where date© =‘2019-05-21’; 優化:改成範圍查询

select * from t1 where c>=‘2019-05-21 0’ and c<=‘2019-05-21 23:59:59’; 隱式轉換 操作符與不同類型的操作對象一同運用時,就會發作類型轉換以使操作兼容。

select user_name,tele_phone from user_info where tele_phone =11111111111; / tele_phone varchar / 實践會做函數操作:

select user_name,tele_phone from user_info where cast(tele_phone as singed int) =11111111111; 優化:類型統一

select user_name,tele_phone from user_info where tele_phone =‘11111111111’; 含糊查询 通配符在前面

select * from t1 where a like ‘%1111%’; 優化:含糊查询必需包含條件字段前面的值

select * from t1 where a like ‘1111%’; 範圍查询 範圍查询數據量太多,需求回表,因而不走索引。

select * from t1 where b>=1 and b <=2000; 優化:降低單次查询範圍,分屢次查询。(實践可能速度沒得快太多,倡議走索引)

select from t1 where b>=1 and b <=1000; show profiles; ±---------±-----------±-----------------------------------------+ | Query_ID | Duration | Query | ±---------±-----------±-----------------------------------------+ | 1 | 0.00534775 | select from t1 where b>=1 and b <=1000 | | 2 | 0.00605625 | select * from t1 where b>=1 and b <=2000 | ±---------±-----------±-----------------------------------------+ 2 rows in set, 1 warning (0.00 sec) 計算操作 即便是简單的計算

explain select * from t1 where b-1 =1000; 優化:將計算操作放在等號後面

explain select * from t1 where b =1000 + 1;

翻了很多题解,只能看懂这种解法,够直观够暴力。

class Solution { public: vector<string> restoreIpAddresses(string s) { vector<string> res;

     for (int a = 1; a < 4; a ++ )
        for (int b = 1; b < 4; b ++ )
            for (int c = 1; c < 4; c ++ )
                for (int d = 1; d < 4; d ++ )           //abcd分别表示四段ip地址长度
                {
                    if (a + b + c + d == s.size())      //四段长度刚好
                    {
                        string s1 = s.substr(0, a);     //分别截取四段ip地址
                        string s2 = s.substr(a, b);
                        string s3 = s.substr(a + b, c);
                        string s4 = s.substr(a + b + c);

                        if (check(s1) && check(s2) && check(s3) && check(s4))
                        {
                            string ip = s1 + '.' + s2 + '.' + s3 + '.' + s4;
                            res.push_back(ip);
                        }
                    }
                }

    return res;
}

bool check(string s)        //判断ip地址每段的第一位不为0,或只有一位且该位为0
{
    if (stoi(s) <= 255)
        if (s[0] != '0' || (s[0] == '0' && s.size() == 1)) return true;

    return false;
} 

}; 下一篇:【切割问题都可以用回溯搜索来解决】详解! © 著作权归作者所有 1 条评论

最热

编辑 预览

评论

阿兹卡班在逃犯 L2 2021-03-13 贴一个java的

class Solution { public List<String> restoreIpAddresses(String s) { List<String> list = new ArrayList(); for(int a=1; a<4; a++){ for(int b=1; b<4; b++){ for(int c=1; c<4; c++){ for(int d=1; d<4; d++){ if(a+b+c+d==s.length()){ String s1 = s.substring(0, a); String s2 = s.substring(a, a+b); String s3 = s.substring(a+b, a+b+c); String s4 = s.substring(a+b+c, a+b+c+d);

                         if(check(s1)&&check(s2)&&check(s3)&&check(s4)){
                            String ip = s1+"."+s2+"."+s3+"."+s4;
                            list.add(ip);
                        }
                    }
                }
            }
        }
    }
    return list;
}

public boolean check(String s){
    if(Integer.valueOf(s)<=255){
        if(s.charAt(0)!='0' || s.charAt(0)=='0'&&s.length()==1) 
            return true;
    }
    return false;
} 

}

查看更多关于算法训练营的详细内容...

  阅读:33次