Skip to content

Commit 93dcb44

Browse files
committed
leetcode 125
1 parent 16c55e8 commit 93dcb44

3 files changed

+173
-0
lines changed

LeetCode/125. Valid Palindrome.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
7+
8+
/* ascii value
9+
A=65,Z=90,a=97,z=122
10+
*/
11+
12+
/* --------------------MAIN PROGRAM----------------------------*/
13+
// to run ctrl+b
14+
const ll INF=1e18;
15+
const ll mod1=1e9+7;
16+
const ll mod2=998244353;
17+
// Techniques :
18+
// divide into cases, brute force, pattern finding
19+
// sort, greedy, binary search, two pointer
20+
// transform into graph
21+
22+
// Experience :
23+
// Cp is nothing but only observation and mathematics.
24+
25+
26+
//Add main code here
27+
28+
class Solution
29+
{
30+
public:
31+
bool isPalindrome(string s)
32+
{
33+
string finalString="";
34+
for(auto x:s)
35+
{
36+
if((x>='a'&&x<='z')||(x>='A'&&x<='Z')||(x>='0'&&x<='9'))
37+
{
38+
if(x>='A'&&x<='Z')
39+
x+=32;
40+
finalString+=x;
41+
}
42+
}
43+
s=finalString;
44+
reverse(finalString.begin(),finalString.end());
45+
46+
if(finalString==s)
47+
return true;
48+
else
49+
return false;
50+
}
51+
};
52+
53+
/* -----------------END OF PROGRAM --------------------*/
54+
/*
55+
* stuff you should look before submission
56+
* constraint and time limit
57+
* int overflow
58+
* special test case (n=0||n=1||n=2)
59+
* don't get stuck on one approach if you get wrong answer
60+
*/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
7+
8+
/* ascii value
9+
A=65,Z=90,a=97,z=122
10+
*/
11+
12+
/* --------------------MAIN PROGRAM----------------------------*/
13+
// to run ctrl+b
14+
const ll INF=1e18;
15+
const ll mod1=1e9+7;
16+
const ll mod2=998244353;
17+
// Techniques :
18+
// divide into cases, brute force, pattern finding
19+
// sort, greedy, binary search, two pointer
20+
// transform into graph
21+
22+
// Experience :
23+
// Cp is nothing but only observation and mathematics.
24+
25+
26+
//Add main code here
27+
28+
class Solution
29+
{
30+
public:
31+
int pivotInteger(int n)
32+
{
33+
int sum=(n*(n+1))/2;
34+
for(int i=1;i<=n;i++){
35+
int tmepSum1=(i*(i+1))/2;
36+
int tempSum2=sum+i-tmepSum1;
37+
if(tmepSum1==tempSum2){
38+
return i;
39+
}
40+
}
41+
return -1;
42+
}
43+
};
44+
45+
/* -----------------END OF PROGRAM --------------------*/
46+
/*
47+
* stuff you should look before submission
48+
* constraint and time limit
49+
* int overflow
50+
* special test case (n=0||n=1||n=2)
51+
* don't get stuck on one approach if you get wrong answer
52+
*/
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
7+
8+
/* ascii value
9+
A=65,Z=90,a=97,z=122
10+
*/
11+
12+
/* --------------------MAIN PROGRAM----------------------------*/
13+
// to run ctrl+b
14+
const ll INF=1e18;
15+
const ll mod1=1e9+7;
16+
const ll mod2=998244353;
17+
// Techniques :
18+
// divide into cases, brute force, pattern finding
19+
// sort, greedy, binary search, two pointer
20+
// transform into graph
21+
22+
// Experience :
23+
// Cp is nothing but only observation and mathematics.
24+
25+
26+
//Add main code here
27+
28+
class Solution
29+
{
30+
public:
31+
int appendCharacters(string s, string t)
32+
{
33+
int j=0;
34+
for(int i=0;i<t.size();i++){
35+
bool flag=false;
36+
for(;j<s.size();j++){
37+
if(s[j]!=t[i]){
38+
continue;
39+
}
40+
else{
41+
flag=true;
42+
j++;
43+
break;
44+
}
45+
}
46+
if(flag==false){
47+
return t.size()-i;
48+
}
49+
}
50+
return 0;
51+
}
52+
};
53+
54+
/* -----------------END OF PROGRAM --------------------*/
55+
/*
56+
* stuff you should look before submission
57+
* constraint and time limit
58+
* int overflow
59+
* special test case (n=0||n=1||n=2)
60+
* don't get stuck on one approach if you get wrong answer
61+
*/

0 commit comments

Comments
 (0)