Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ed65ade

Browse files
/
1 parent 29dd40c commit ed65ade

15 files changed

+359
-17
lines changed

‎Add_minimum-Char_palindrome.cpp‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
/* https://practice.geeksforgeeks.org/problems/55d */
4+
5+
6+
int addMinChar(string str){
7+
//code here
8+
int n=str.length();
9+
int i=0;
10+
int j=n-1;
11+
int ans=0;
12+
while(i<=j)
13+
{
14+
if(str[i]==str[j])
15+
{
16+
i++;
17+
j--;
18+
}
19+
else
20+
{
21+
ans++;
22+
i=0;
23+
j=n-1-ans;
24+
}
25+
}
26+
27+
28+
return ans;
29+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* https://leetcode.com/problems/count-the-number-of-consistent-strings/description/ */
2+
3+
class Solution {
4+
public:
5+
int countConsistentStrings(string allowed, vector<string>& words) {
6+
7+
int count=0;
8+
for(int i=0;i<words.size();i++)
9+
{
10+
for(int j=0;j<words[i].size();j++)
11+
{
12+
if(allowed.find(words[i][j])!=string::npos)
13+
{
14+
15+
}
16+
else
17+
{
18+
count++;
19+
break;
20+
}
21+
}
22+
}
23+
return words.size()-count;
24+
}
25+
};

‎Integer_To_Roman.cpp‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ class Solution{
1717
public:
1818
string convertToRoman(int n) {
1919
// code here
20-
int num[]={1,4,5,9,10,40,50,90,100,400,500,900,1000};
21-
string s[]={"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"};
22-
string ans;
23-
int i=12;
24-
while(n>0)
25-
{
26-
int div=n/num[i];
27-
n=n%num[i];
28-
while(div--)
29-
{
30-
ans=ans+s[i];
31-
}
32-
i--;
33-
}
34-
return ans;
20+
vector<string> notations = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
21+
vector<int> value = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
22+
string s;
23+
int i=0;
24+
while(num!=0)
25+
{
26+
if(num>=value[i])
27+
{
28+
s=s+notations[i];
29+
num=num-value[i];
30+
}
31+
else{
32+
i++;
33+
}
34+
}
35+
return s;
3536
}
3637
};

‎Longest_Balance_Binary_String.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
/* https://leetcode.com/problems/find-the-longest-balanced-substring-of-a-binary-string/*/
3+
class Solution {
4+
public:
5+
int findTheLongestBalancedSubstring(string s) {
6+
int res=0;
7+
string temp="01";
8+
while(temp.size()<=s.size())
9+
{
10+
if(s.find(temp)!=string::npos){
11+
res=temp.size();
12+
}
13+
temp='0'+temp+'1';
14+
}
15+
return res;
16+
17+
}
18+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*https://leetcode.com/problems/longest-substring-without-repeating-characters/description/*/
2+
3+
4+
5+
class Solution {
6+
public:
7+
int lengthOfLongestSubstring(string s) {
8+
unordered_set<char>set;
9+
int i=0,j=0,n=s.length();
10+
int maxi=0;
11+
12+
while(i<n && j<n)
13+
{
14+
if(set.find(s[j])==set.end())
15+
{
16+
set.insert(s[j]);
17+
j++;
18+
maxi=max(maxi,j-i);
19+
20+
}
21+
else
22+
{
23+
set.erase(s[i]);
24+
i++;
25+
}
26+
}
27+
28+
return maxi;
29+
}
30+
31+
};

‎Maximum_Length.cpp‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* https://practice.geeksforgeeks.org/problems/84963d7b5b84aa24f7807d86e672d0f97f41a4b5/1 */
2+
3+
4+
class Solution {
5+
public:
6+
int solve(int a, int b, int c) {
7+
// code here || (b >(a+c)(a+c+1)/2) || (a>(b+c)(b+c+1)/2))
8+
if( (c>2*(a+b)) || (b >2*(a+c)) || (a>2*(b+c)))
9+
{
10+
return -1;
11+
}
12+
else
13+
{
14+
return a+b+c;
15+
}
16+
17+
}
18+
};

‎README.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@
2525
- transform(s.begin(), s.end(), s.begin(), ::tolower);
2626
- transform(s.begin(), s.end(), s.begin(), ::toupper);
2727

28-
- Find:- s1.find(s2[i]):- it means <find s2[i] in s1>
28+
- Find:- s1.find(s2[i])!=string::npos:- it means <find s2[i] in s1> is present
29+
30+
- token:- stringstream
31+
ex: string s = "geeks for geeks";
32+
stringstream ss(s); // Used for breaking words
33+
string word; // to store individual words
34+
while (ss >> word)
35+
cout << word << endl;
36+
37+
2938

3039

‎Remove_Stars_From_String.cpp‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* https://leetcode.com/problems/removing-stars-from-a-string/description/ */
2+
3+
class Solution {
4+
public:
5+
string removeStars(string s) {
6+
stack<char>st;
7+
for(char c:s)
8+
{
9+
10+
if(!st.empty() && c=='*')
11+
{
12+
st.pop();
13+
}
14+
else
15+
{
16+
st.push(c);
17+
}
18+
19+
}
20+
string ans;
21+
while(!st.empty())
22+
{
23+
ans+=st.top();
24+
st.pop();
25+
}
26+
reverse(ans.begin(),ans.end());
27+
28+
return ans;
29+
}
30+
};

‎Reverse_Word_in_String.cpp‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,26 @@ mno.pqr
5656
ans1=ans1+i;
5757
}
5858
return ans1+t;
59-
}
59+
}
60+
61+
62+
// https://leetcode.com/problems/reverse-words-in-a-string
63+
64+
65+
string reverseWords(string s) {
66+
stringstream ss(s);
67+
string word;
68+
vector<string>v;
69+
while(ss>>word)
70+
{
71+
v.push_back(word);
72+
v.push_back(" ");
73+
}
74+
v.pop_back();
75+
reverse(v.begin(),v.end());
76+
string ans;
77+
for(auto i:v)
78+
{
79+
ans=ans+i;
80+
}
81+
return ans;

‎Roman_To_Integer.cpp‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* https://leetcode.com/problems/roman-to-integer/ */
2+
3+
4+
class Solution {
5+
public:
6+
int romanToInt(string s) {
7+
8+
9+
unordered_map<char,int>m;
10+
m['I']=1;
11+
m['V']=5;
12+
m['X']=10;
13+
m['L']=50;
14+
m['C']=100;
15+
m['D']=500;
16+
m['M']=1000;
17+
18+
19+
int ans=0;
20+
for(int i=0;i<s.length();i++)
21+
{
22+
if(m[s[i]]>=m[s[i+1]] )
23+
{
24+
ans=ans+m[s[i]];
25+
}
26+
else{
27+
ans=ans-m[s[i]];
28+
}
29+
}
30+
return ans;
31+
32+
}
33+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /