Skip to content

Commit 95e607e

Browse files
committed
leetcode
1 parent 330e3cd commit 95e607e

File tree

3 files changed

+149
-13
lines changed

3 files changed

+149
-13
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
string s,temp;
22+
cin>>s;
23+
temp=s;
24+
reverse(temp.begin(),temp.end());
25+
s+=temp;
26+
cout<<s<<endl;
27+
return 0;
28+
}
29+
int main()
30+
{
31+
long long testCase;
32+
cin>>testCase;
33+
while(testCase--){
34+
solve();
35+
}
36+
return 0;
37+
}
38+
/* -----------------END OF PROGRAM --------------------*/
39+
/*
40+
* stuff you should look before submission
41+
* constraint and time limit
42+
* int overflow
43+
* special test case (n=0||n=1||n=2)
44+
* don't get stuck on one approach if you get wrong answer
45+
*/
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
/* ascii value
11+
A=65,Z=90,a=97,z=122
12+
*/
13+
14+
// Techniques :
15+
// divide into cases, brute force, pattern finding
16+
// sort, greedy, binary search, two pointer
17+
// transform into graph
18+
19+
20+
int solve(){
21+
int n;
22+
cin>>n;
23+
if(n&1){
24+
while(n--){
25+
cout<<2<<" ";
26+
}
27+
cout<<endl;
28+
}
29+
else{
30+
while(n>2){
31+
cout<<2<<" ";
32+
n--;
33+
}
34+
cout<<"1 3"<<endl;
35+
}
36+
return 0;
37+
}
38+
int main()
39+
{
40+
long long testCase;
41+
cin>>testCase;
42+
while(testCase--){
43+
solve();
44+
}
45+
return 0;
46+
}
47+
/* -----------------END OF PROGRAM --------------------*/
48+
/*
49+
* stuff you should look before submission
50+
* constraint and time limit
51+
* int overflow
52+
* special test case (n=0||n=1||n=2)
53+
* don't get stuck on one approach if you get wrong answer
54+
*/

LeetCode/202.Happy_Number.cpp

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,62 @@
1-
class Solution {
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+
{
230
public:
3-
bool isHappy(int n) {
4-
map<int,int> m;
5-
while(1)
31+
bool isHappy(int n)
32+
{
33+
map<int, int> m;
34+
while (1)
635
{
7-
if(n==1)
36+
if (n == 1)
837
return true;
9-
else if(m[n])
38+
else if (m[n])
1039
return false;
1140
else
1241
{
1342
m[n]++;
14-
int temp=0;
15-
while(n)
43+
int temp = 0;
44+
while (n)
1645
{
17-
temp+=(n%10)*(n%10);
18-
n/=10;
46+
temp += (n % 10) * (n % 10);
47+
n /= 10;
1948
}
20-
n=temp;
21-
// cout<<"n "<<n<<endl;
49+
n = temp;
2250
}
2351
}
2452
}
25-
};
53+
};
54+
55+
/* -----------------END OF PROGRAM --------------------*/
56+
/*
57+
* stuff you should look before submission
58+
* constraint and time limit
59+
* int overflow
60+
* special test case (n=0||n=1||n=2)
61+
* don't get stuck on one approach if you get wrong answer
62+
*/

0 commit comments

Comments
 (0)