id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "typedef std::pair<std::string, int> pairs;\nstd::vector<pairs> map_roman = {{\"I\",1},{\"IV\",4},{\"V\",5},{\"IX\",9},\n {\"X\",10},{\"XL\",40},{\"L\",50},{\"XC\",90},\n {\"C\",100}, {\"CD\",400},{\"D\",500},{\"CM\",900},\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n void createRomanMap(vector<int>& map){\n map['I'-'A'] = 1, map['V'-'A'] = 5;\n map['X'-'A'] = 10, map['L'-'A'] = 50;\n map['C'-'A'] = 100, map['D'-'A'] = 500;\n map['M'-'A'] = 1000;\n }\n\n int romanToInt(string s) {\n vector<int> hmap... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n // I->1, V->5, X->10, C->100, D->500, L->1000\n // DXCII-> 500+90+2->\n vector<int> mp(26, 0);\n mp['I'-'A'] = 1;\n mp['V'-'A'] = 5;\n mp['X'-'A'] = 10;\n mp['L'-'A'] = 50;\n mp['C'-'A'] = 10... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n constexpr auto create_mapping = []() constexpr {\n array<int, 26> mapping = {0};\n array<char, 7> letters = {\n 'I', 'V', 'X', 'L', 'C', 'D', 'M'\n };\n array<int, 7> values = {\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n int len = s.length();\n string sub_str;\n int sum = 0;\n for (int i = 0; i < len; i++)\n {\n if (i != len - 1)\n {\n if (s[i] == 'I' || s[i] == 'X' || s[i] == 'C')\n {\n sub_str... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n int arr[26]={0};\n arr[2]=100;\n arr[3]=500;\n arr[8]=1;\n arr[11]=50;\n arr[12]=1000;\n arr[21]=5;\n arr[23]=10;\n\n int res=0;\n for(int i=0;i<s.length();i++)\n {\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n int solution = 0;\n int value = 0;\n\n for (int i=0; i < s.length() - 1; i++){\n\n value = getLetterValue(s[i]);\n\n if (isSubtracting(s[i], s[i+1])){\n solution -= value;\n }\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n int val = 0;\n int length = s.size();\n\n int values[128];\n values['I'] = 1;\n values['V'] = 5;\n values['X'] = 10;\n values['L'] = 50;\n values['C'] = 100;\n values['D'] = 500;\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n int m[1000];\n m['I'] = 1;\n m['V'] = 5;\n m['X'] = 10;\n m['L'] = 50;\n m['C'] = 100;\n m['D'] = 500;\n m['M'] = 1000;\n int ans = 0;\n for(int i=0;i<s.size();i++){\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution{\npublic:\n int romanToInt(string s){\n int values[1001];\n values[0+'I']=1;\n values[0+'V']=5;\n values[0+'X']=10;\n values[0+'L']=50;\n values[0+'C']=100;\n values[0+'D']=500;\n values[0+'M']=1000;\n int sum=values[int(s[0])... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n vector<char> chrList = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};\n vector<int> numList = {1, 5, 10, 50, 100, 500, 1000};\n \n int getValue(string s, int loc){\n if(loc >= s.size()) return -1;\n \n for(int i = 0; i < chrList.size(); i++)\n i... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\nprivate:\n std::vector<char> m_symbolRoman{'I', 'V', 'X', 'L', 'C', 'D', 'M'};\n std::vector<int> m_valueInteger{1, 5, 10, 50, 100, 500, 1000};\npublic:\n int romanToInt(string s) {\n //assert(m_symbolRoman.size() == m_valueInteger.size());\n\n int sum{0};\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution\n{\npublic:\n vector<pair<char, int>> wordMap = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};\n\n int getVal(char ch)\n {\n for (pair<char, int> K : wordMap)\n {\n if (K.first == ch)\n {\n return K... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> nums{\n {'I', 1},\n {'V', 5},\n {'X', 10},\n {'L', 50},\n {'C', 100},\n {'D', 500},\n {'M', 1000},\n };\n int ans = nums[s.b... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n \n int romanToInt(string s) {\n unordered_map<char,int> m={{'I',1},{'V',5},{'X',10},{'L',50},{'C',100},{'D',500},{'M',1000}};\n int ans=0;\n for(int i=s.size()-1;i>=0; i--){\n ans+=m[s[i]];\n if(i-1>=0&&m[s[i-1]]<m[s[i]]){\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> romanMap = {\n {'I', 1}, {'V', 5}, {'X', 10},\n {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}\n };\n \n int total = 0;\n int n = s.length();\n \n for ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> nums{\n {'I', 1},\n {'V', 5},\n {'X', 10},\n {'L', 50},\n {'C', 100},\n {'D', 500},\n {'M', 1000},\n };\n int ans = nums[s.b... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(std::string s)\n {\n\n\n std::unordered_map<char, int> roman =\n {\n {'I', 1},\n {'V', 5},\n {'X', 10},\n {'L', 50},\n {'C', 100},\n {'D', 500},\n {'M', 1000}\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 0 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> nums{\n {'I', 1},\n {'V', 5},\n {'X', 10},\n {'L', 50},\n {'C', 100},\n {'D', 500},\n {'M', 1000},\n };\n int ans = nums[s.b... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 1 | {
"code": "class Solution\n{\n std::unordered_map<char, int> romans = {\n { 'M', 1000 },\n { 'D', 500 },\n { 'C', 100 },\n { 'L', 50 },\n { 'X', 10 },\n { 'V', 5 },\n { 'I', 1 },\n };\n\npublic:\n int romanToInt(std::string s)\n {\n return solutionMa... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 1 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> map = {\n { 'I', 1 },\n { 'V', 5 },\n { 'X', 10 },\n { 'L', 50 },\n { 'C', 100 },\n { 'D', 500 },\n { 'M', 1000 }\n };\n\n i... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 1 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> map = {{'I', 1}, {'V', 5}, {'X', 10}, {'L', 50}, {'C', 100}, {'D', 500}, {'M', 1000}};\n\n int res = map[s[s.size()-1]];\n\n for(int i= s.size()-2; i>=0; i--){\n if(map[s[i]]>=map[s[i+1]]){\... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 1 | {
"code": "class Solution {\n public:\n int romanToInt(string s) {\n int ans = 0;\n vector<int> roman(128);\n\n roman['I'] = 1;\n roman['V'] = 5;\n roman['X'] = 10;\n roman['L'] = 50;\n roman['C'] = 100;\n roman['D'] = 500;\n roman['M'] = 1000;\n\n for (int i = 0; i + 1 < s.length(); ++... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 1 | {
"code": "class Solution {\n public:\n int romanToInt(string s) {\n int ans = 0;\n vector<int> roman(128);\n\n roman['I'] = 1;\n roman['V'] = 5;\n roman['X'] = 10;\n roman['L'] = 50;\n roman['C'] = 100;\n roman['D'] = 500;\n roman['M'] = 1000;\n\n for (int i = 0; i + 1 < s.length(); ++... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 1 | {
"code": "class Solution {\n public:\n int romanToInt(string s) {\n int ans = 0;\n vector<int> roman(128);\n\n roman['I'] = 1;\n roman['V'] = 5;\n roman['X'] = 10;\n roman['L'] = 50;\n roman['C'] = 100;\n roman['D'] = 500;\n roman['M'] = 1000;\n\n for (int i = 0; i + 1 < s.length(); ++... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 1 | {
"code": "class Solution {\n public:\n int romanToInt(string s) {\n int ans = 0;\n vector<int> roman(128);\n\n roman['I'] = 1;\n roman['V'] = 5;\n roman['X'] = 10;\n roman['L'] = 50;\n roman['C'] = 100;\n roman['D'] = 500;\n roman['M'] = 1000;\n\n for (int i = 0; i + 1 < s.length(); ++... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\n public:\n int romanToInt(string s) {\n int ans = 0;\n vector<int> roman(128);\n\n roman['I'] = 1;\n roman['V'] = 5;\n roman['X'] = 10;\n roman['L'] = 50;\n roman['C'] = 100;\n roman['D'] = 500;\n roman['M'] = 1000;\n\n for (int i = 0; i + 1 < s.length(); ++... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\n public:\n int romanToInt(string s) {\n int ans = 0;\n vector<int> roman(128);\n\n roman['I'] = 1;\n roman['V'] = 5;\n roman['X'] = 10;\n roman['L'] = 50;\n roman['C'] = 100;\n roman['D'] = 500;\n roman['M'] = 1000;\n\n for (int i = 0; i + 1 < s.length(); ++... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\n public:\n int romanToInt(string s) {\n int ans = 0;\n vector<int> roman(128);\n\n roman['I'] = 1;\n roman['V'] = 5;\n roman['X'] = 10;\n roman['L'] = 50;\n roman['C'] = 100;\n roman['D'] = 500;\n roman['M'] = 1000;\n\n for (int i = 0; i + 1 < s.length(); ++... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> mp;\n mp['I'] = 1;\n mp['V'] = 5;\n mp['X'] = 10;\n mp['L'] = 50;\n mp['C'] = 100;\n mp['D'] = 500;\n mp['M'] = 1000;\n \n int sum = 0;\n for (in... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> umap;\n umap['I'] = 1;\n umap['V'] = 5;\n umap['X'] = 10;\n umap['L'] = 50;\n umap['C'] = 100;\n umap['D'] = 500;\n umap['M'] = 1000;\n vector<int> v;\n\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n std::map<char, int> map = {\n {'I', 1},\n {'V', 5},\n {'X', 10},\n {'L', 50},\n {'C', 100},\n {'D', 500},\n {'M', 1000}\n };\n\n int result = 0;\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n\n \n\n int romanToInt(string s) {\n\n map<char, int> numeralMap;\n\n numeralMap['I'] = 1;\n numeralMap['V'] = 5;\n numeralMap['X'] = 10;\n numeralMap['L'] = 50;\n numeralMap['C'] = 100;\n numeralMap['D'] = 500;\n nume... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> mp;\n\n mp['I'] = 1;\n mp['V'] = 5;\n mp['X'] = 10;\n mp['L'] = 50;\n mp['C'] = 100;\n mp['D'] = 500;\n mp['M'] = 1000;\n\n int n =... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> m;\n \n m['I'] = 1;\n m['V'] = 5;\n m['X'] = 10;\n m['L'] = 50;\n m['C'] = 100;\n m['D'] = 500;\n m['M'] = 1000;\n \n int ans = 0;\n \n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> m;\n \n m['I'] = 1;\n m['V'] = 5;\n m['X'] = 10;\n m['L'] = 50;\n m['C'] = 100;\n m['D'] = 500;\n m['M'] = 1000;\n \n int ans = 0;\n \n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> m;\n \n m['I'] = 1;\n m['V'] = 5;\n m['X'] = 10;\n m['L'] = 50;\n m['C'] = 100;\n m['D'] = 500;\n m['M'] = 1000;\n \n int ans = 0;\n \n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 2 | {
"code": "class Solution {\npublic:\n int romanToInt(string c) {\n unordered_map<char, int> m;\n \n m['I'] = 1;\n m['V'] = 5;\n m['X'] = 10;\n m['L'] = 50;\n m['C'] = 100;\n m['D'] = 500;\n m['M'] = 1000;\n int ans=0;\n\n for(int i=0;i<... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 3 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char,int>roman;\n roman['I']=1;\n roman['V']=5;\n roman['X']=10;\n roman['L']=50;\n roman['C']=100;\n roman['D']=500;\n roman['M']=1000;\n\n int ans=0;\n for(int i... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 3 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n unordered_map<char, int> m;\n \n m['I'] = 1;\n m['V'] = 5;\n m['X'] = 10;\n m['L'] = 50;\n m['C'] = 100;\n m['D'] = 500;\n m['M'] = 1000;\n \n int ans = 0;\n \n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 3 | {
"code": "class Solution {\npublic:\n\n \n\n int romanToInt(string s) {\n\n map<char, int> numeralMap; // create map for conversion\n\n numeralMap['I'] = 1;\n numeralMap['V'] = 5;\n numeralMap['X'] = 10;\n numeralMap['L'] = 50;\n numeralMap['C'] = 100;\n numeral... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 3 | {
"code": "class Solution {\npublic:\n int romanToInt(string s) {\n map<char,int>mp;\n mp['I']=1;\n mp['V']=5;\n mp['X']=10;\n mp['L']=50;\n mp['C']=100;\n mp['D']=500;\n mp['M']=1000;\n int res=0;\n for(int i=0;i<s.length();i++)\n {\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 3 | {
"code": "class Solution {\npublic:\n int romanToInt(string str) {\n map<char, int> m;\n m.insert({ 'I', 1 });\n m.insert({ 'V', 5 });\n m.insert({ 'X', 10 });\n m.insert({ 'L', 50 });\n m.insert({ 'C', 100 });\n m.insert({ 'D', 500 });\n m.insert({ 'M', 1000 });\n int sum = 0;\n ... |
13 | <p>Roman numerals are represented by seven different symbols: <code>I</code>, <code>V</code>, <code>X</code>, <code>L</code>, <code>C</code>, <code>D</code> and <code>M</code>.</p>
<pre>
<strong>Symbol</strong> <strong>Value</strong>
I 1
V 5
X 10
L 50
C ... | 3 | {
"code": "#include <iostream>\n#include <string>\n#include <vector>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int romanToInt(const string& s) {\n // Define the mapping from Roman numerals to integers\n vector<string> roman = {\"M\", \"CM\", \"D\", \"CD\", \"C\", \"XC\", \"L\", \"XL\", \... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\n public:\n string longestCommonPrefix(vector<string>& strs) {\n if (strs.empty())\n return \"\";\n\n for (int i = 0; i < strs[0].length(); ++i)\n for (int j = 1; j < strs.size(); ++j)\n if (i == strs[j].length() || strs[j][i] != strs[0][i])\n return strs[0... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int sizeVector = strs.size();\n string subString = \"\";\n int mid = strs[0].length();\n \n for(int j = 0; j < mid; ++j){\n int mark = 0;\n for(int i = 1; i < sizeVec... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution\n{\npublic:\n string longestCommonPrefix(vector<string>& vct)\n {\n if (vct.size() == 1) { return vct[0]; }\n \n int size = vct[0].size(); string answer = \"\"; int count = 0; int index = 0;\n\n for (int i = 0; i < vct.size(); i++)\n {\n if... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int min = INT_MAX;\n int that = 0;\n for (int i = 0;i<strs.size();i++){\n if (strs[i].size()<min){\n min = strs[i].size();\n that = i;\n }\n }\... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int min = INT_MAX;\n int that = 0;\n for (int i = 0;i<strs.size();i++){\n if (strs[i].size()<min){\n min = strs[i].size();\n that = i;\n }\n }\... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string result;\n bool stop = false;\n int prefix_size = 0;\n if(strs.empty())\n return result;\n while(stop == false && prefix_size<strs.at(0).size())\n {\n if... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string result;\n if(strs.empty())\n return result;\n int loop_time = INT_MAX;\n int strs_size = strs.size();\n for(int i = 0;i < strs_size; i++)\n {\n if(strs.... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n sort(strs.begin(),strs.end());\n int n = strs.size();\n string a= strs[0];\n string b = strs[n-1];\n string c=\"\";\n for (int i = 0; i< min(a.size(), b.size()); i++){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string baseStr = strs[0];\n int ans = 0 ;\n \n for(int j = 0 ; j < baseStr.size() ; j++){\n bool matched = true ; \n for(int i =1 ; i < strs.size() ; i++){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string s=\"\";\n lon(strs,0,s);\n return s;\n }\n void lon(vector<string>&strs,int start ,string& s){\n for(int i=0;i<strs.size();i++){\n if(start>=strs[i].size()||strs[0][start]... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 0 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n if (strs.size() == 0) return \"\"; \n string prefix = strs[0];\n\n for (int i = 1; i < strs.size(); i++) {\n while (strs[i].find(prefix) != 0) {\n prefix = prefix.substr(0, pre... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 1 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n \n \n int mini=INT_MAX;\n string small=\"\";\n for (auto i:strs){\n if (i.length()<mini){\n mini=i.length();\n small=i;\n }\n }\n string... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 1 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n if (strs.empty()) return \"\";\n string prefix = strs[0];\n for (int i = 1; i < strs.size(); i++) {\n while (strs[i].find(prefix) != 0) {\n prefix = prefix.substr(0, prefix.size() - 1); \n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 2 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& v) {\n string ans=\"\";\n sort(v.begin(),v.end());\n int n=v.size();\n string first=v[0],last=v[n-1];\n for(int i=0;i<min(first.size(),last.size());i++){\n if(first[i]!=last[i]){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 2 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int len = INT_MAX;\n for(auto x:strs){\n len = len > x.size() ? x.size():len ;\n }\n\n cout << len;\n int cnt = 0;\n bool brk = false;\n for(int j = 0; j < len; j... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 2 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string ans = \"\";\n sort(strs.begin(), strs.end());\n int n = strs.size();\n string first = strs[0], last = strs[n-1];\n for(int i=0; i<min(first.size(), last.size()); i++) {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Node{\n public:\n Node* links[26];\n bool flag;\n int childs;\n\n Node(){\n for(int i =0; i<26; i++) links[i] = NULL;\n flag = false;\n childs = 0;\n }\n\n bool containsKey(char c){\n return links[c-'a'] != NULL;\n }\n\n Node* get(char c){\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class trie\n{\n public:\n bool isLeaf;\n struct trie* child[26];\n trie()\n {\n isLeaf = false;\n for (int i = 0; i <26; i++)\n {\n child[i] = NULL;\n }\n }\n\n void insert(string input)\n {\n trie* cur = this;\n for (int i = 0; i... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int n = strs.size();\n int last = 0;\n if(strs.size() == 1) return strs[0];\n string res = find_common_prefix(strs[0], strs[1]);\n if( res == \"\") return res;\n for(int i=1; i<n; i... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n if(strs.size()==0)return \"\";\n if(strs.size()==1)return strs[0];\n char ch;\n string ans=\"\";\n for(int i=0;i<200;i++){\n string str=strs[0];\n if(i>=str.size()) r... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int n = strs.size();\n if(!n) return \"\";\n string req = strs[0];\n for(int i=1;i<n;i++){\n string prev = strs[i-1];\n string curr = strs[i];\n string temp =\"\";\n for(int j... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n if (strs.size() == 1) {\n return strs[0];\n }\n // int min_size = 201;\n // for (const auto& s : strs) {\n // min_size = std::min(min_size, s.size());\n // }\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string func_CommonStr(string s1, string s2){\n \n int i = 0, n = s1.size(), m = s2.size() ;\n string ans = \"\" ;\n \n while(i < n && i < m){\n if(s1[i] == s2[i])\n ans += s1[i] ;\n else break ;\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Node{\n public:\n char val;\n vector<Node*>children;\n bool isend;\n Node(char val): val(val){\n children = vector<Node*>(26, nullptr);\n isend=false;\n }\n};\nclass Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n\n string prefix = \"\";\n\n if (strs.size() == 0)\n {\n return prefix;\n }\n\n if (strs.size() == 1)\n {\n return strs[0];\n }\n\n int indexOfStr... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string compare_prefixes(string s1, string s2){\n int c=0, min;\n int n1 = s1.size(), n2 = s2.size();\n string minstr, maxstr;\n if (n1<n2){\n minstr = s1;\n maxstr = s2;\n min = n1;\n }\n else{\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n if (strs.empty()) return \"\";\n\n int minLen = strs[0].length();\n for (const string& str : strs) {\n minLen = min(minLen, (int)str.length());\n }\n\n unordered_map<int, unorde... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Trie\n{\n public:\n int cnt;\n bool isLeaf;\n unordered_map<char, Trie*> son;\n \n Trie()\n {\n cnt = 0;\n isLeaf = false;\n }\n \n void insert(string& word)\n {\n Trie* current = this;\n int n = word.size();\n \n for(int i = ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nstatic const int nSize = 26;\nstruct Node{\n vector<int> children;\n bool isLast;\n Node(){\n children = vector<int>(nSize, -1);\n isLast = false;\n }\n};\n\nstruct Trie{\n vector<Node> mainTrie;\n string actualLongestPrefi... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class TrieNode {\npublic:\n std::unordered_map<char, TrieNode*> children;\n bool isEndOfWord;\n\n TrieNode() : isEndOfWord(false) {}\n};\n\n\nclass Trie {\npublic:\n TrieNode* root;\n\n Trie() {\n root = new TrieNode();\n }\n\n void insert(const std::string& word) {\n Tri... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "\n class TrieNode{\n public:\n unordered_map<char, TrieNode*> children;\n char val;\n bool isWord = false;\n\n TrieNode(){}\n TrieNode(char v){\n this->val = v;\n }\n };\n\n class Trie{\n private:\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class TrieNode{\n public:\n int val;\n unordered_map<int,TrieNode*> children;\n bool isTerminal;\n \n TrieNode(int val){\n this->val = val;\n this->isTerminal = false;\n }\n};\n\nvoid insert(TrieNode* root,string word) {\n int index = 0;\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string findPrefix(string str1, string str2) {\n string ans;\n \n int i = 0, j = 0;\n int n = str1.size(), m = str2.size();\n \n while (i < n && j < m) {\n if (str1[i] == str2[j]) {\n ans += str1[i];\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string findPrefix(string str1, string str2) {\n string ans;\n \n int i = 0, j = 0;\n int n = str1.size(), m = str2.size();\n \n while (i < n && j < m) {\n if (str1[i] == str2[j]) {\n ans += str1[i];\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) \n {\n int n=strs.size();\n string res=\"\";\n unordered_map<string, int> mp;\n for(int i=0;i<n;i++)\n {\n string temp=\"\";\n for(auto it:strs[i])\n {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) \n {\n int n=strs.size();\n string res=\"\";\n unordered_map<string, int> mp;\n for(int i=0;i<n;i++)\n {\n string temp=\"\";\n for(auto it:strs[i])\n {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) \n {\n int n=strs.size();\n string res=\"\";\n unordered_map<string, int> mp;\n for(int i=0;i<n;i++)\n {\n string temp=\"\";\n for(auto it:strs[i])\n {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) \n {\n int n=strs.size();\n string res=\"\";\n unordered_map<string, int> mp;\n for(int i=0;i<n;i++)\n {\n string temp=\"\";\n for(auto it:strs[i])\n {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class TrieNode {\npublic:\n unordered_map<char, TrieNode*> children;\n};\n\nclass Trie {\nprivate:\n TrieNode* root = new TrieNode;\npublic:\n void insert(string word) {\n TrieNode* curr = this->root;\n\n for (char c : word) {\n if (!curr->children.count(c)) {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n // Helper function to find the common prefix between two strings\n string commonPrefix(const string& str1, const string& str2) {\n int minLength = min(str1.length(), str2.length());\n for (int i = 0; i < minLength; ++i) {\n if (str1[i] != str2[i]) ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) \n {\n int n=strs.size();\n string res=\"\";\n map<string, int> mp;\n for(int i=0;i<n;i++)\n {\n string temp=\"\";\n for(auto it:strs[i])\n {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string divideAndSolve(vector<string>& str, int start, int end) {\n if (start == end) return str[start];\n\n int mid = start + (end - start) / 2;\n string LCPofLeft = divideAndSolve(str, start, mid);\n string LCPofRight = divideAndSolve(str, mid + ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\nprivate:\n string lcp(vector<string>& strs, int begin, int end) {\n if (end == begin + 1) {\n return strs[begin];\n }\n\n int mid = (begin + end) / 2;\n string lcpLeft = lcp(strs, begin, mid);\n string lcpRight = lcp(strs, mid, end);\n\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string> &strs) {\n return aux(strs, 0, strs.size());\n }\n\nprivate:\n string aux(vector<string> &strs, size_t begin, size_t end) {\n size_t n = end - begin;\n if (n == 1) {\n return strs[begin];\n } else if (n == 2) {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution;\nclass Node{\n char data;\n int rep;\n unordered_map<char, Node*> m;\n bool isTerminal;\n public:\n Node(char d){\n data = d;\n rep = 0;\n isTerminal = false;\n }\n\n friend class Solution; \n};\n\nclass Solution {\nNode* ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n if (strs.size() == 1) return strs[0];\n int len = strs.size();\n string s1 = strs[len-1];\n string s2 = strs[len-2];\n\n if (s1.length() == 0 || s2.length() == 0) return \"\";\n\n s... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string lcp(string &s1,string &s2){\n int i,j,n=s1.length(),m=s2.length();\n i=0;j=0;\n while(i<n && j<m){\n if(s1[i] != s2[j]) break;\n i++;j++;\n }\n return s1.substr(0, min(i,j));\n }\n string get(vector<string>... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n bool areEqual(string str1, string str2){\n if(str1.size() != str2.size()) return 0;\n for(int i=0; i<str1.size(); i++){\n if(str1[i] != str2[i]) return 0;\n }\n return 1;\n }\n string longestCommonPrefix(vector<string>& strs) {\n ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n string str;\n\n for(size_t i = strs[0].length(); i > 0; i--)\n {\n str = string(strs[0], 0, i);\n size_t j = 1;\n for(; j < strs.size() and !str.compare(string(strs... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n static bool compare(string s1, string s2){\n if(s1.length() < s2.length())\n return true;\n else return false;\n }\n string longestCommonPrefix(vector<string>& strs) {\n sort(strs.begin(), strs.end(), compare);\n int n = strs[0].le... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n // size_t longestPrefix = 0;\n string str;\n\n for(size_t i = strs[0].length(); i > 0; i--)\n {\n str = string(strs[0], 0, i);\n // cout << \"---> \"<< str << endl;\n... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n std::string st = strs[0], answer = \"\";\n int k = 0;\n for (int i = st.length(); i > 0; i--) {\n for (int j = 1; j < strs.size(); j++) {\n if (strs[j].find(st.substr(0, i)) ==... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\n static bool cmp(string s1,string s2){\n return s1.length()< s2.length();\n }\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int n=strs.size();\n if(n==0) return \"\";\n if(n==1) return strs[0];\n string ans=\"\";\n sort(... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\n static bool cmp(string s1,string s2){\n return s1.length()< s2.length();\n }\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n int n=strs.size();\n if(n==0) return \"\";\n if(n==1) return strs[0];\n string ans=\"\";\n sort(... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n static bool comparator(string str1, string str2){\n return str1.size() < str2.size();\n }\n string longestCommonPrefix(vector<string>& strs) {\n string substring = \"\";\n sort(strs.begin(),strs.end(),comparator);\n // the largest prefix can ... |
14 | <p>Write a function to find the longest common prefix string amongst an array of strings.</p>
<p>If there is no common prefix, return an empty string <code>""</code>.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong> strs = ["flower","flow&quo... | 3 | {
"code": "class Solution {\npublic:\n string longestCommonPrefix(vector<string>& strs) {\n sort(strs.begin(),strs.end(),[](string A,string B){return A.size()<B.size();});\n string str=strs[0];\n str.push_back('0');\n for(int i=0;i<str.size()+2;i++){\n str.pop_back();\n ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.