ecem_assignment#94
Conversation
| class Solution { | ||
| public: | ||
| int mySqrt(int x) { | ||
| if(x==0){ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
you do not have to declare the variable central as double. i.e. int is enough.
|
|
||
|
|
||
| } | ||
| }; No newline at end of file |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Kodun güzel ama commentleri biraz daha detaylandırabilirmişsin.
No description provided.