adding leetcode problem solution

This commit is contained in:
Jidong Xiao
2024-01-16 13:39:24 -05:00
parent 94a69a8524
commit b5cb9cbdd8
3 changed files with 28 additions and 3 deletions

View File

@@ -130,4 +130,4 @@ cost of copying.
- [Leetcode problem 8: String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/)
- [Leetcode problem 211: Design Add and Search Words Data Structure](https://leetcode.com/problems/design-add-and-search-words-data-structure/)
- [Leetcode problem 1662: Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/)
- [Leetcode problem 1662: Check If Two String Arrays are Equivalent](https://leetcode.com/problems/check-if-two-string-arrays-are-equivalent/) Solution: [p1662_check_two_strings.cpp](../../leetcode/p1662_check_two_strings.cpp)

View File

@@ -27,14 +27,14 @@
## 3.3 Class scope notation
In the *Date* class example as you saw in lab 2,
In the *Date* class example as you see in lab 2,
- **Date::** indicates that what follows is within the scope of the class.
- Within class scope, the member functions and member variables are accessible without the name of the object.
## 3.4 Constructors
These are special functions that initialize the values of the member variables. The constructor automatically get called when an object of the class is created. You have already used constructors for string and vector objects. As you have seen in the lab, constructors in C++ have the following characteristics:
These are special functions that initialize the values of the member variables. The constructor automatically get called when an object of the class is created. You have already used constructors for string and vector objects. As you see in the lab, constructors in C++ have the following characteristics:
- Constructors have the same name as the class they belong to.
- They do not have a return type, not even void.

View File

@@ -0,0 +1,25 @@
class Solution {
public:
bool arrayStringsAreEqual(vector<string>& word1, vector<string>& word2) {
std::string s1="";
std::string s2="";
unsigned int size = word1.size();
// traverse word1 and concatenate all strings
// save it in s1
for(unsigned int i=0;i<size;i++){
s1 = s1 + word1[i];
}
size = word2.size();
// traverse word2 and concatenate all strings
// save it in s2
for(unsigned int i=0;i<size;i++){
s2 = s2 + word2[i];
}
// if they are equivanent
if(s1==s2){
return true;
}else{
return false;
}
}
};