Summary of 66 Programming Questions in "Sword Finger offer"

Articles Catalogue

(Question 21) Numbers that appear more than half of the time in an array

September 7, 2019 01:48:22

The Title links are as follows:
https://www.nowcoder.com/practice/e8a1b01a2df14cb2b228b30ee6a92163?tpId=13&tqId=11181&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: September 7, 2019 01:36:46                                                 
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: 7 September 2019 01:43:34                                          
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <time.h>
#include <algorithm>
using namespace std;

class Solution {
public:
	int MoreThanHalfNum_Solution(vector<int> numbers)
	{
		if (numbers.size() < 1)
			throw"vector is empty!";

		unordered_map<int, int>mymap;
		for (int val : numbers)
		{
			mymap[val]++;
		}
		int size = numbers.size();
		for (unordered_map<int, int>::iterator it = mymap.begin();
			it != mymap.end(); ++it)
		{
			if (it->second > size / 2)
				return it->first;
		}
		return 0;
	}
};

int main()
{
	Solution solution;	

	int Array[] = { 1,2,3,2,2,2,5,4,2 };
	int Array1[] = { 1,2,3,4,5,8,5,4,2 };
	vector<int>myvec(begin(Array), end(Array));
	vector<int>myvec1(begin(Array1), end(Array1));

	cout << solution.MoreThanHalfNum_Solution(myvec) << endl;
	cout << solution.MoreThanHalfNum_Solution(myvec1) << endl;
	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 01:51:58

(Question 22) The smallest number of k

September 7, 2019 02:09:50

The Title links are as follows:
https://www.nowcoder.com/practice/6a296eb82cf844ca8539b57c23e6e9bf?tpId=13&tqId=11182&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: September 7, 2019 01:59:11                                                 
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: 7 September 2019 02:03:47                                           
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <time.h>
#include <algorithm>
using namespace std;

class Solution {
public:
	vector<int> GetLeastNumbers_Solution(vector<int> input, int k) 
	{
		vector<int>myvec;
		int size = input.size();
		if (size < 1 || k > size)
			return myvec;	

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

		for (int i = 0; i < k; ++i)
		{
			myvec.push_back(input[i]);
		}
		return myvec;
	}
};

int main()
{
	Solution solution;	

	int Array[] = { 1,2,3,2,2,2,5,4,2 };
	int Array1[] = { 4,5,1,6,2,7,3,8 };
	vector<int>myvec(begin(Array), end(Array));
	vector<int>myvec1(begin(Array1), end(Array1));

	vector<int>result1 = solution.GetLeastNumbers_Solution(myvec, 8);
	vector<int>result2 = solution.GetLeastNumbers_Solution(myvec1, 4);

	for (int val : result1)
		cout << val << " ";
	cout << endl;

	for (int val : result2)
		cout << val << " ";
	cout << endl;
	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 02:12:08

Note: I can't write any more. I got up at 10:30 yesterday noon and began to study at 11 o'clock. So far, I have only had one meal (half an hour), and the rest of the time I have been offer ing by brushing my sword and finger. I think I have already had 22 questions on AC. It feels good, but my computer has been with me for seven years, an old-fashioned computer (i3 processor). Sorry, my computer has been working hard with someone in Song Dynasty. Now that the computer is hot, you can fry the egg. I'll wipe it with some water.
Note: 360 browsers can't work properly. Haha ha ha has a Chrome which is not commonly used. Learn it every day after sleeping!!!

(Question 23) Ugly Number

September 7, 2019, 10:59:42

The Title links are as follows:
https://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b?tpId=13&tqId=11186&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: September 7, 2019, 10:23:32                                                
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: September 7, 2019, 10:55:48                                           
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <time.h>
#include <algorithm>
using namespace std;

//First divide by 2 until it is not divisible, then divide by 5 until it is not divisible, and then divide by 3 until it is not divisible.
//Ultimately determine whether the remaining number is 1, if it is 1, it is ugly, otherwise it is not ugly.
//That is to say, ugly number = ugly number * ugly number
//The first ugly number is 1
//The first 20 clowns are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36.
//So judging the ugly number of index is to find the number in the sequence above.
/*
So the idea of the algorithm is that every time an ugly number is put in myvec, three ugly numbers can be derived.


The above sequences (except a1=1) can be divided into three categories, which must satisfy the following requirements:
Ordered sequence of ugly numbers containing 2: 2*a1, 2*a2, 2*a3...
Ordered ugly sequence containing 3: 3*a1, 3*a2, 3*a3...
Ordered ugly sequence containing 5: 5*a1, 5*a2, 5*a3...
The total number of the above three sequences is n, and a1 = 1 is known.
The above three sequences can be merged into an ordered sequence.
t2,t3,t5 in the program are actually the sorted field indexes in the three sequences in the merging process

The core is to get the result according to the known, and then regard the result as known, and find the next ugly number. Until the target result appears

Note: Merging results require orderly sequences
 Such as:
a1=1,a2 The source is the minimum 2 in 2*a1 3*a1 5*a1.
a2=2,a3 The source is the minimum 3 in 2*a2 3*a1 5*a1.
a3=3,a4 The source is the minimum 4 in 2*a2 3*a2 5*a1.
a4=4,a5 The source is the minimum value of 5 in 2*a3*a2 5*a1.


Wait a minute. It's an ordered sequence.
*/
class Solution {
public:
	int GetUglyNumber_Solution(int index) 
	{
		vector<int>myvec;

		if (index < 7)
			return index;
		myvec.push_back(1);//1 is the first ugly number
		int indexof_2 = 0, indexof_3 = 0, indexof_5 = 0;
		for (int i = 1; i < index; ++i)
		{
			myvec.push_back(min(2 * myvec[indexof_2], 
					min(3 * myvec[indexof_3], 5 * myvec[indexof_5])));
			if (myvec[i] == 2 * myvec[indexof_2])
				indexof_2++;
			if (myvec[i] == 3 * myvec[indexof_3])
				indexof_3++;
			if (myvec[i] == 5 * myvec[indexof_5])
				indexof_5++;
		}
		return myvec[index - 1];
	}
};

int main()
{
	Solution solution;	

	cout << "The 20th Ugly Number:" << solution.GetUglyNumber_Solution(20) << endl;
	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 11:02:04

(Question 24) The first character that appears only once

September 7, 2019 11:40:02

The Title links are as follows:
https://www.nowcoder.com/practice/1c82e8cf713b4bbeb2a5b31cf5b0417c?tpId=13&tqId=11187&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: 11:03:35 September 7, 2019                                               
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: September 7, 2019 11:39:11                                     
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <time.h>
#include <algorithm>
using namespace std;


class Solution {
public:
	int FirstNotRepeatingChar(string str) 
	{
		int size = str.size();
		if (size == 0)
			return -1;
		unordered_map<char, int>mymap;

		for (int i = 0; i < size; ++i)
		{
			mymap[str[i]]++;
		}
#if 0
		unordered_map<char, int>::iterator it = mymap.begin();
		for (; it != mymap.end(); ++it)
		{
			if (it->second == 1)
				break;
		}
		if (it == mymap.end())
			return -1;
		for (int i = 0; i < size; ++i)
		{
			if (str[i] == it->first)
				return i;
		}
#endif
		for (int i = 0; i < size; ++i)
		{
			if (mymap[str[i]] == 1)
				return i;
		}
		return -1;
	}
};

int main()
{
	Solution solution;	

	string mystr("bAbcddeaa");
	string mystr1("gg");
	cout << "The position of the first character that appears only once:" << solution.FirstNotRepeatingChar(mystr) << endl;
	cout << "The position of the first character that appears only once:" << solution.FirstNotRepeatingChar(mystr1) << endl;
	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 11:41:47
It could have been done in six minutes, but it took 36 minutes. What's more, it was the mistake made by Temo at noon yesterday. I commented that piece in the code, so you can also consider why not? If you don't think you've thought about it.

(Question 25) Inverse Pairs in Arrays

September 7, 2019 15:19:38

Note: To write this topic, first refer to my blog:
The fifth of the top ten sorting algorithms in DSA: Merge Sort
The Title links are as follows:
https://www.nowcoder.com/practice/96bd6684e04a44eb80e6a68efc0ec6c5?tpId=13&tqId=11188&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: September 7, 2019 11:45:33                                             
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Ending time:                                     
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <time.h>
#include <algorithm>
using namespace std;


class Solution {
public:
	void devide_and_conquer(vector<int>&src,int low,int high,long *count_num)
	{
		if (low >= high)
			return;

		int mid = low + (high - low) / 2;
		devide_and_conquer(src, low, mid, count_num);
		devide_and_conquer(src, mid + 1, high, count_num);

		int i = low, j = mid + 1, k = 0;//k is the subscript of a temporary array
		vector<int>temp_vec(high - low + 1);
		while (i <= mid && j <= high)
		{
			if (src[i] > src[j])
			{
				//Now that this element is in the position of j, it has more mid+1-i in front of it than it does.
				//After moving the data, the current inverse order of the decimal does not exist.
				//SRC [i] > a [j], so this time,
				//From src[i] to src[mid] must be larger than this src[j],
				//Because by this time the two sides of the divide and rule are already in their own order.
				//This is the most important step:
				*count_num = (mid - i + 1 + *count_num) % 1000000007;
				temp_vec[k++] = src[j++];
			}
			else
			{
				temp_vec[k++] = src[i++];
			}
		}
		while (i <= mid)
		{
			temp_vec[k++] = src[i++];
		}
		while (j <= high)
		{
			temp_vec[k++] = src[j++];
		}

		//The next step is to copy the sorted data back.
		k = 0;
		for (int i=low;i<=high;++i)
		{
			src[i] = temp_vec[k++];
		}
	}
	int InversePairs(vector<int> &data) 
	{
		int size = data.size();
		if (size <= 1)
			return 0;
		long count_num = 0;

		devide_and_conquer(data, 0, size - 1, &count_num);
		return (int)count_num % 1000000007;
	}
};

int main()
{
	Solution solution;	
	int Array[] = { 1,2,3,4,5,6,7,0 };
	//int Array1[] = { 1,2,3,4,5,6,7,8 };
	int Array1[] = { 4,5,2,1 };

	vector<int>myvec(begin(Array), end(Array));
	vector<int>myvec1(begin(Array1), end(Array1));

	cout << "Inverse order pair number:" << solution.InversePairs(myvec) << endl;
	cout << "Inverse order pair number:" << solution.InversePairs(myvec1) << endl;
	
	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 15:23:07

Number Number Number Number Number Number Number Number Number Number Number Number Number Number Number Number Number Number Number Number Number

September 7, 2019 15:30:56

The Title links are as follows:
https://www.nowcoder.com/practice/70610bf967994b22bb1c26f9ae901fa2?tpId=13&tqId=11190&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: September 7, 2019 15:26:06                                            
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: September 7, 2019 15:29:20                                   
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <time.h>
#include <algorithm>
using namespace std;


class Solution {
public:
	int GetNumberOfK(vector<int> &data, int k) 
	{
		int size = data.size();
		if (size == 0)
			return 0;

		unordered_map<int, int>mymap;
		for (int val : data)
		{
			mymap[val]++;
		}
		auto it = mymap.find(k);
		if (it != mymap.end())
		{
			return it->second;
		}
		else
			return 0;
	}
};
int main()
{
	Solution solution;	
	
	
	return 0;
}

/**
*Standby Notes:
*
*
*
*/


September 7, 2019 15:32:38

The first common node of two linked lists

September 7, 2019 16:34:52

The Title links are as follows:
https://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46?tpId=13&tqId=11189&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: September 7, 2019 15:32:38                                            
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: September 7, 2019 16:33:43                                   
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <time.h>
#include <algorithm>
using namespace std;


struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :val(x), next(nullptr) {}
};
class Solution {
public:
	/*
	Common nodes show that the value of common nodes is the same as next, so there must be a common tail.
	Meaning: let the long go first two lists of different lengths, and then go together.
	*/
	ListNode* FindFirstCommonNode(ListNode* pHead1, ListNode* pHead2)
	{
		if (pHead1 == nullptr || pHead2 == nullptr)
			return nullptr;
	
		ListNode* this_first_p = nullptr;

		vector<int>myvec1; ListNode* p1 = pHead1;
		vector<int>myvec2; ListNode* p2 = pHead2;

		while (p1 != nullptr)
		{
			myvec1.push_back(p1->val);
			p1 = p1->next;
		}
		while (p2 != nullptr)
		{
			myvec2.push_back(p2->val);
			p2 = p2->next;
		}
		int size1 = myvec1.size();
		int size2 = myvec2.size();
		
		p1 = pHead1;
		p2 = pHead2;
		if (size1 <= size2)
		{
			int i = 0;
			for (; i < size2 - size1; ++i)//Take a few steps first
			{
				p2 = p2->next;
			}
			for (; i < size2; ++i)
			{
				if (p1->val == p2->val && p1->next == p2->next)
				{
					return p1;
				}
				p1 = p1->next;
				p2 = p2->next;
			}
			return nullptr;
		}
		else
		{
			int i = 0;
			for (; i < size1 - size2; ++i)//Take a few steps first
			{
				p1 = p1->next;
			}
			for (; i < size1; ++i)
			{
				if (p1->val == p2->val && p1->next == p2->next)
				{
					return p1;
				}
				p1 = p1->next;
				p2 = p2->next;
			}
			return nullptr;
		}
	}
};
int main()
{
	Solution solution;	
	int Array1[] = { 8,7,3,5,6,5,4,3,2 };
	int Array2[] = {         7,5,4,3,2 };
	
	ListNode* phead1 = new ListNode(8);//Do Long Chain Well
	ListNode* cur_p = phead1;
	for (int i = 1; i < 9; ++i)
	{
		ListNode* p = new ListNode(Array1[i]);
		cur_p->next = p;
		cur_p = cur_p->next;
	}

	ListNode* phead2 = new ListNode(7);//Make short chains
	cur_p = phead1;
	for (int i = 0; i < 5; ++i)
	{
		cur_p = cur_p->next;
	}
	phead2->next = cur_p;
	cur_p = solution.FindFirstCommonNode(phead1, phead2);
	if (cur_p != nullptr)
	{
		cout << "Common nodes of two linked lists val: " << cur_p->val << endl;
	}
	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 16:37:22

(Question 28) Array arrays into the smallest number

September 7, 2019 17:09:49

The Title links are as follows:
https://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993?tpId=13&tqId=11185&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: September 7, 2019 16:40:06                                            
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: 7 September 2019 17:05:09                                   
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <time.h>
#include <algorithm>
using namespace std;


class Solution {
public:
	/*
	1.to_string() is used to convert int into string
	2.Provide a custom comparison for sort
	*/
	//Customize compare_of_2int function to sort vector s'data
	static bool compare_of_2int(int a, int b)
	{
		string str_a = to_string(a);
		string str_b = to_string(b);

		return (str_a + str_b) < (str_b + str_a);
	}
	string PrintMinNumber(vector<int> numbers) 
	{
		string result;
		int size = numbers.size();
		if (size < 1)
		{
			return result;
		}

		//Sort the data in vector in the way above
		sort(numbers.begin(), numbers.end(), compare_of_2int);

		for (int val : numbers)
		{
			result += to_string(val);
		}
		
		return result;
	}
};
int main()
{
	Solution solution;	
	int Array1[] = { 3,32,321 };
	vector<int>myvec(begin(Array1), end(Array1));

	cout << solution.PrintMinNumber(myvec) << endl;

	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 17:12:27

Number of occurrences of 1 in integers

September 7, 2019 17:09:49

The Title links are as follows:
https://www.nowcoder.com/practice/bd7f978302044eee894445e244c7eee6?tpId=13&tqId=11184&tPage=2&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: 7 September 2019 17:12:27                                            
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: 7 September 2019 17:21:33                                   
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <time.h>
#include <algorithm>
using namespace std;



class Solution {
public:
	int NumberOf1Between1AndN_Solution(int n)
	{
		if (n < 1)
			return 0;

		int count = 0;
		for (int i = 1; i <= n; ++i)
		{
			string str_i = to_string(i);
			for (char c : str_i)
			{
				if (c == '1')
					count++;
			}
		}
		return count;
	}
};
int main()
{
	Solution solution;	
	
	cout << "1 reach n There are altogether:" 
					<< solution.NumberOf1Between1AndN_Solution(13) << endl;
	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 17:24:41

(Question 30) Finding 1+2+3+-+n (Limited)

September 7, 2019 17:55:14

The Title links are as follows:
https://www.nowcoder.com/practice/7a0da8fc483247ff8800059e12d7caf1?tpId=13&tqId=11200&tPage=3&rp=3&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
Title Description:

The code is as follows:

/**══════════════════════════════════╗
*Author: song jinzhou_
*CSND Address: https://blog.csdn.net/weixin_43949535_
**GitHub: https://github.com/TsinghuaLucky912/My_own_C-_study_and_blog║
*═══════════════════════════════════╣
*Creation time: 17:30:59 September 7, 2019                                            
*Functional description:                                                            
*                                                                      
*                                                                      
*═══════════════════════════════════╣
*Closing time: 7 September 2019 17:56:31                                    
*═══════════════════════════════════╝
//                .-~~~~~~~~~-._       _.-~~~~~~~~~-.
//            __.'              ~.   .~              `.__
//          .'//              Southwest . / United Nations General Assembly .
//        .'//                     |                     \\`.
//      .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
//    .'//.-"                 `-.  |  .-'                 "-.\\`.
//  .'//______.============-..   \ | /   ..-============.______\\`.
//.'______________________________\|/______________________________`.
*/


#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <time.h>
#include <algorithm>
using namespace std;


class Solution {
public:
	int Sum_Solution(int n)
	{
		int result = n;
		//You can only use short-circuit calculations to exit recursion
		//But the drawback is obvious: recursive layers can't be too deep to be less than 3000
		
		n && (result += Sum_Solution(n - 1));
		return result;
	}
};
/*
n=5 result=result+sun(4);-------5+10
n=4 result=result+sun(3);-------4+6
n=3 result=result+sun(2);-------3+3
n=2 result=result+sun(1);-------2+1
n=1 result=result+sun(0);  -----1+0
n=0 result=result+sun(-1);----->0   

*/
int main()
{
	Solution solution;	
	
	cout << solution.Sum_Solution(5) << endl;
	return 0;
}

/**
*Standby Notes:
*
*
*
*/



September 7, 2019 17:57:19

Tags: github REST less

Posted on Sat, 07 Sep 2019 03:07:26 -0700 by kuri7548