MySQL基础教程

安装后修改密码

安装mysql后修改密码

MySQL连接

使用mysql -u root -p 连接,-u指定用户root,-p 密码选项,如果设置了密码需要加-p选项

连接方式一

[root ~]#mysql -u root -proot

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 10

S......

[LeetCode C++实现]43. Multiply Strings

AC代码:

class Solution {

public:

string multiply(string num1, string num2) {

string res(num1.size()+num2.size(),'0');

for(int i = num1.size() - 1;i >= 0;i--)

{

int carry = 0;

for(int j = num2.size() - 1;j >= 0;j--)

{

int tmp = res[i+j+1]-'0' + (num1[i] - '0')*(num2[j]-'0') + carry;

res[i+j+1]......

[LeetCode C++实现]148. Sort List

首先我们使用一种便于理解的方法,将链表一分为二,然后归并排序,再合并两个有序链表。

/**

* Definition for singly-linked list.

* struct ListNode {

* int val;

* ListNode *next;

* ListNode() : val(0), next(nullptr) {}

* ListNode(int x) : val(x), next(nullptr) {}

* ListNode(int x, ListNode *next) : val(x), next(next) {}

* ......

[LeetCode C++实现]16. 3Sum Closest

与leetcode15题目类似,大方向是使用双指针 三指针求解问题,细节稍有不同,AC代码如下:

class Solution {

public:

int threeSumClosest(vector<int>& nums, int target) {

int n = nums.size();

sort(nums.begin(),nums.end());

int min_val = INT_MAX;

int res = 0;

for(int i = 0;i < n - 2;i++){

int second = i + 1;

int third = n -1;......

[LeetCode C++实现]1502. Can Make Arithmetic Progression From Sequence

方法一:排序

class Solution {

public:

bool canMakeArithmeticProgression(vector<int>& arr) {

sort(arr.begin(),arr.end());

int diff = arr[1] - arr[0];

for(int i = 1;i < arr.size();i++)

{

if(arr[i] - arr[i-1] != diff)

return false;

}

return true;

}

};

运行效率:

Runtime: 4 ms, faster than 65......

[LeetCode C++实现]151. Reverse Words in a String

class Solution {

public:

string reverseWords(string s) {

int size = s.size();

int i = 0,j = 0;

while(i < size)

{

//skip spaces

while(i < size && s[i] == ' ')

i++;

if(i < size && j > 0)

s[j++] = ' ';

int start = j;

while(i < size && s[i] != ' ')

s[j++] = s[i++];......

[LeetCode C++实现]1551. Minimum Operations to Make Array Equal

比较直观好理解的解法:

class Solution {

public:

int minOperations(int n) {

int res = 0;

for(int i = 1;i <= n;i++)

{

int num = 2*(i-1) + 1;

if(num > n)

res += num -n;

}

return res;

}

};

运行效率:

Runtime: 0 ms, faster than 100.00% of C++ online submissions for Minimum Operations to Make Array Equal......

[LeetCode C++实现]319. Bulb Switcher

最直观最容易想的方法,暴力破解方法:

class Solution {

public:

int bulbSwitch(int n) {

vector<int> state(n,0);

for(int i = 1;i <= n;i++)

{

for(int j = i-1;j < n;j += i)

{

state[j] ^= 1;

}

}

return count(state.begin(),state.end(),1);

}

};

执行结果:

Time Limit Exceeded

Details

Last executed input

10000......

[LeetCode C++实现]1773. Count Items Matching a Rule

最直观的解法:

class Solution {

public:

int countMatches(vector<vector<string>>& items, string ruleKey, string ruleValue) {

int index = (ruleKey == "type")? 0 : (ruleKey == "color") ? 1: 2;

int res = 0;

for(int i = 0;i < items.size();i++)

{

if(items[i][index] == ruleValue)

res += 1;

}......

[LeetCode C++实现]1381. Design a Stack With Increment Operation

先使用最直观的解法:

class CustomStack {

public:

CustomStack(int maxSize) {

m_maxsize = maxSize;

}

void push(int x) {

if(m_elem.size() >= m_maxsize)

return;

m_elem.push(x);

}

int pop() {

if(m_elem.empty())

return -1;

int x = m_elem.top();

m_elem.pop();

return x;

}

void increment(int k, int val) {

sta......