-
-
Notifications
You must be signed in to change notification settings - Fork 443
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
Create palindrome.dart #187
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
void main(){ | ||
print('Enter Words or number'); | ||
// User enter a string or a number | ||
String? original = 'hannah'; | ||
|
||
// then we will reverse the input | ||
String? reverse = original.split('').reversed.join(''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid printing |
||
// then we will compare | ||
if(original == reverse) | ||
{ | ||
print('Its A Palindrome'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. write tests. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am very new to this. What are tests? I will be updating everything as you requested There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can check out other files. to see how tests are implemented. You can also read up from the official docs: |
||
}else{ | ||
print('Its A Not Palindrome'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we optimise this? can we have an algorithm with lesser space complexity? Also reduce the use of inbuilt functions like reversed. split and join. The Algorithm will be quite inefficient. |
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a function outside main which checks for palindrome.