Skip to content

Commit 4cfdee4

Browse files
Add files via upload
1 parent e58a508 commit 4cfdee4

11 files changed

+268
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//NOT MINE
2+
public class Polynomial {
3+
4+
private int[] cof;
5+
private int deg;
6+
7+
public Polynomial() {
8+
cof=new int[5];
9+
deg=-1;
10+
}
11+
public void setCoefficient(int deg,int coficient) {
12+
if(deg >=cof.length) {
13+
restructure(deg);
14+
}
15+
cof[deg]=coficient;
16+
if(deg >= this.deg) {
17+
this.deg=deg;
18+
}
19+
}
20+
public Polynomial add(Polynomial p) {
21+
22+
Polynomial x=new Polynomial();
23+
24+
int i=0,j=0,k=0;
25+
while(i < p.cof.length && j < this.cof.length) {
26+
x.setCoefficient(k, p.cof[i] + this.cof[i]);
27+
i++;
28+
j++;
29+
k++;
30+
}
31+
while(i<p.cof.length) {
32+
x.setCoefficient(k, p.cof[i]);
33+
k++;
34+
i++;
35+
}
36+
while(j<this.cof.length) {
37+
x.setCoefficient(k, this.cof[j]);
38+
k++;
39+
j++;
40+
}
41+
42+
43+
return x;
44+
45+
}
46+
public Polynomial subtract(Polynomial p) {
47+
48+
Polynomial x=new Polynomial();
49+
50+
int i=0,j=0,k=0;
51+
while(i < p.cof.length && j < this.cof.length) {
52+
x.setCoefficient(k, this.cof[i] - p.cof[i] );
53+
i++;
54+
j++;
55+
k++;
56+
}
57+
while(i<p.cof.length) {
58+
x.setCoefficient(k, -p.cof[i]);
59+
k++;
60+
i++;
61+
}
62+
while(j<this.cof.length) {
63+
x.setCoefficient(k, this.cof[j]);
64+
k++;
65+
j++;
66+
}
67+
68+
69+
return x;
70+
71+
}
72+
public Polynomial multiply(Polynomial p) {
73+
74+
Polynomial x=new Polynomial();
75+
76+
for(int i=0;i<p.cof.length;i++) {
77+
for(int j=0;j<this.cof.length;j++) {
78+
if(i + j <=x.deg)
79+
x.setCoefficient( i + j ,x.cof[i+j]+p.cof[i] * this.cof[j]);
80+
else
81+
x.setCoefficient(i + j ,p.cof[i] * this.cof[j]);
82+
}
83+
}
84+
return x;
85+
86+
}
87+
public void print() {
88+
for(int i=0;i<cof.length;i++) {
89+
if(cof[i] !=0)
90+
System.out.print( cof[i] +"x"+ i +" ");
91+
}
92+
}
93+
private void restructure(int deg) {
94+
95+
int[] temp=cof;
96+
cof=new int[deg + 1];
97+
for(int i=0;i<temp.length;i++) {
98+
cof[i]=temp[i];
99+
}
100+
}
101+
102+
103+
104+
105+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class Solution {
2+
public static int countWords(String str) {
3+
if(str.length()==0) return 0;
4+
String[] s1=str.split(" ");
5+
return s1.length;
6+
}
7+
8+
}

15.String/1.Count Words.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class Solution {
2+
3+
public static int countWords(String str) {
4+
if(str.length()==0) return 0;
5+
6+
int spaces=0;
7+
8+
for (int i = 0; i < str.length(); i++)
9+
if (str.charAt(i)==' ') spaces++;
10+
11+
12+
return spaces+1;
13+
}
14+
15+
}

15.String/2.String Palindrome.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
public class Solution {
3+
4+
public static boolean isPalindrome(String str) {
5+
int len=str.length()-1;
6+
String a= "";
7+
for (int i = len; i >=0 ; i--) {
8+
a+=(str.charAt(i));
9+
}
10+
// System.out.println(a);
11+
return a.equals(str);
12+
}
13+
14+
}

15.String/3.All substrings.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
public class Solution {
3+
4+
public static void printSubstrings(String str) {
5+
for (int i = 0; i < str.length(); i++) {
6+
for (int j = i; j < str.length(); j++) {
7+
for (int k = i; k <=j; k++) {
8+
System.out.print(str.charAt(k));
9+
}
10+
System.out.println();
11+
}
12+
}
13+
}
14+
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Solution {
2+
public static String reverseWordWise(String input) {
3+
String[] arrOdStr=input.split(" ");
4+
String reverseWord="";
5+
for (int i = arrOdStr.length-1;i >=0 ; i--) {
6+
reverseWord+=arrOdStr[i]+" ";
7+
}
8+
return reverseWord;
9+
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
public class Solution {
3+
4+
public static String removeConsecutiveDuplicates(String str) {
5+
StringBuilder a = new StringBuilder();
6+
for (int i = 0; i < str.length() ; i++) {
7+
a.append(str.charAt(i));
8+
if (i<str.length()-1){
9+
while (str.charAt(i) == str.charAt(i + 1)) {
10+
i++;
11+
if (i>=str.length()-1) break;
12+
}
13+
}
14+
}
15+
return a.toString();
16+
}
17+
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
public class Solution {
3+
4+
public static String reverseEachWord(String str) {
5+
String[] ArrStr=str.split(" ");
6+
String mynewStr=new String("");
7+
for (String s : ArrStr) {
8+
for (int j = s.length() - 1; j >= 0; j--) {
9+
mynewStr += s.charAt(j);
10+
}
11+
mynewStr += " ";
12+
}
13+
return mynewStr;
14+
}
15+
16+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
public class Solution {
3+
4+
public static String removeAllOccurrencesOfChar(String str, char ch) {
5+
String c1=""+ch;
6+
return str.replace(c1,"");
7+
8+
}
9+
10+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
public class Solution {
3+
4+
public static char highestOccuringChar(String str) {
5+
char[] uniqueArr=new char[str.length()-1];
6+
char MaxOcc=str.charAt(0);
7+
int Bcount =1;
8+
int count;
9+
for (int i = 0; i < str.length(); i++) { count =0;
10+
boolean skipThis=false;
11+
for(char ele:uniqueArr){
12+
if (str.charAt(i) == ele) {
13+
skipThis = true;
14+
break;
15+
}
16+
}
17+
18+
if (skipThis) continue;
19+
else uniqueArr[i]=str.charAt(i);
20+
21+
for (int j = i; j < str.length(); j++) {
22+
if (str.charAt(i)==str.charAt(j)) count++;
23+
}
24+
25+
if (count>Bcount) {
26+
MaxOcc=str.charAt(i);
27+
Bcount=count;
28+
}
29+
}
30+
return MaxOcc;
31+
}
32+
33+
}

0 commit comments

Comments
 (0)