Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bhit #349

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion c/p11.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int isSameTree(struct TreeNode* p, struct TreeNode* q){
return 1;
}
if(p->val == q->val){
return isSameTree(p->left, q->left) || isSameTree(p->right, q->right);
return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
return 0;
}
3 changes: 1 addition & 2 deletions c/p13.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ int main(){

int n = sizeof(a)/sizeof(a[0]);
int m = sizeof(b)/sizeof(b[0]);

for(int i=0;i<n;i++);{
for(int i=0;i<n;i++){
printf("%d ", a[i]);
}
printf("\n");
Expand Down
7 changes: 6 additions & 1 deletion c/p14.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ int romanToInt(char * s){
}
}
int num=0;
for(int i=0;i<strlen(s)-1;i++){
int i;
for(i=0;i<strlen(s)-1;i++){
if(a[i] < a[i+1]){
a[i+1] -= a[i];
i++;
}
num += a[i];
}
if(i==strlen(s)-1)
{
num += a[strlen(s) - 1];
}
return num;
}

Expand Down
4 changes: 2 additions & 2 deletions c/p4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ string caesar(string s, int k, string direction){
string ans = "";
for(int i=0;i<s.length();i++){
if(direction == "encode"){
ans += s[i] + k;
ans += 'a' + (s[i]-'a' + k) % 26;
}
else if(direction == "decode"){
ans += s[i] - k;
ans += 'a' + (s[i]-'a' - k + 26) % 26;
}
}
return ans;
Expand Down
2 changes: 1 addition & 1 deletion c/p5.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ void main(){
int a=10;
int *ptr = &a;

*ptr++;
(*ptr)++;
printf("%d", *ptr);
}
3 changes: 2 additions & 1 deletion c/p6.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
int *fun()
{
int x = 5;
return &x;
int *t=&x
return t;
}
int main()
{
Expand Down
2 changes: 1 addition & 1 deletion c/p8.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
float computeAverage(float* x, size_t* N) {
float numerator = 0.0;
float denominator = 0.0;
for (size_t i = 0; i < (size_t)N; i++) {
for (size_t i = 0; i < *N; i++) {
numerator += x[i];
denominator++;
}
Expand Down
8 changes: 4 additions & 4 deletions c/p9.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
*/

#include <stdio.h>

#include <stdlib.h>
int* filterMultiples(int* arr, int N, int* NOut, int num) {
int numPrimes = 0;
*NOut = 0;
for (int i = 0; i < N; i++) {
if (arr[i] >= num && arr[i]%num == 0) {
*NOut++;
(*NOut)++;
}
}
int* multiples = malloc((*NOut)*sizeof(int));
int* multiples =malloc((*NOut)*sizeof(int));
int idx = 0;
for (int i = 0; i < *NOut; i++) {
for (int i = 0; i < N; i++) {
if (arr[i] >= num && arr[i]%num == 0) {
multiples[idx] = arr[i];
idx++;
Expand Down
1 change: 1 addition & 0 deletions py/p1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
def asterisk_tree(height,level):
if level > height:
return
print(' '*(height-level),end='')
for j in range(2*level-1):
print("*", end="")
print()
Expand Down
3 changes: 2 additions & 1 deletion py/p10.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#Finding Average RGB values using the listmaker fuction to generate list of rgb values for a pixel

def listmaker(r,g,b,list1=[]):
def listmaker(r,g,b):
list1=[]
list1.append(r)
list1.append(g)
list1.append(b)
Expand Down
6 changes: 3 additions & 3 deletions py/p11.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Function to convert decimal to binary number

def binaryconversion(n):
print(n % 2,end = '')
if n > 1:
binaryconversion(n/2)
if n > 1:
binaryconversion(n//2)
print(n%2,end='')

number=int(input("Enter Number: "))
binaryconversion(number)
Expand Down
2 changes: 1 addition & 1 deletion py/p2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# input- 1 -> output- [1], input- 2 -> output- [2]

def add_item(item, items=[]):
items.append(item)
items=[item]
return items

print(add_item(1))
Expand Down
2 changes: 1 addition & 1 deletion py/p3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#eg: [2, 4, 6, 17, 10] -> [17, 10]

def delete_starting_evens(list):
for item in list:
while True:
if list[0] % 2 == 0:
list.pop(0)
else:
Expand Down
4 changes: 2 additions & 2 deletions py/p4.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def countSort(arr):
ans = [0 for i in range(len(arr))]
for i in arr:
count[i] += 1
for i in range(k+1):
for i in range(1,k+1):
count[i] += count[i-1]
for i in range(len(arr)-1, -1, -1):
ans[count[arr[i]]] = arr[i]
ans[count[arr[i]]-1] = arr[i]
count[arr[i]] -= 1
return ans

Expand Down
3 changes: 1 addition & 2 deletions py/p6.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def addBinary(a: str, b: str) -> str:
j -= 1
s.append(str(carry % 2))
carry //= 2

return ''.join(reversed(s))
return str(carry)+''.join(reversed(s))

print(addBinary("11", "0"))
7 changes: 5 additions & 2 deletions py/p9.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ def ispangram(str1, alphabet=string.ascii_lowercase):
alphaset = list(alphabet)

str = list(str1.lower())

for i in ''.join(alphaset):
if i not in ''.join(str):
return False

# Check if all lowercase characters in the input string covers all characters in 'alphaset'
return alphaset <= str
return True

# Print the result of checking if the string is a pangram by calling the 'ispangram' function
print(ispangram('The quick brown fox jumps over the lazy dog'))