Skip to content

ecem_assignment#94

Open
Eijo12 wants to merge 1 commit into
ituacm:mainfrom
Eijo12:main
Open

ecem_assignment#94
Eijo12 wants to merge 1 commit into
ituacm:mainfrom
Eijo12:main

Conversation

@Eijo12

@Eijo12 Eijo12 commented Sep 5, 2023

Copy link
Copy Markdown

No description provided.

class Solution {
public:
int mySqrt(int x) {
if(x==0){

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (x == 0 || x == 1) return x; would be a bit cleaner

//Special case of x=1
int first=1;
int last=x;
double central;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you do not have to declare the variable central as double. i.e. int is enough.



}
}; No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all in all, the code and the algorithm is easy to understand. variable names are self-explaining. comment lines are efficient and helps me to understand.

@@ -0,0 +1,40 @@
//Author: Ecem Özkul

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kod stiline biraz daha önem verebilirsin. parantezlerin içinde boşluklar bırakman vs. daha okunaklı bir kod yaratır.

first=central+1;
}
}
return (int) last; //Returning last as the sqrt(x) because this is the case first>last

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neden int'e cast etme ihtiyacı duydun onu pek anlayamadım. zaten int olarak tanımlanmış gibi

int last=x;
double central;
while(first <= last){
central=first+(last-first)/2; //Finding the center of the number

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double central şeklinde içeride tanımlamak daha güzel olabilir. çünkü üst scope'da değişken kullanılmıyor

@@ -0,0 +1,28 @@
//Author: Ecem Özkul
//Question Link: https://leetcode.com/problems/count-and-say/
//Time Complexity: O(2^N)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Time complexity 2^n değil n^2, recursive function kendini 1 kez çağırıyor ve her loopta n kadar haneye bakıyor, n^2 o yüzden time complexity.

} //Special case of n=1
string previous = countAndSay(n-1); //Recursive function calls itself for countAndSay(n-1)
string result= ""; //Defining result
int count=1; //Defining a count variable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kodun güzel ama commentleri biraz daha detaylandırabilirmişsin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants