Java Program To Find First Non Repeated Character | Java | Ashok IT
ฝัง
- เผยแพร่เมื่อ 15 พ.ค. 2020
- ✍️✍️ Register Here For Online Training : bit.ly/3Crpgbr
** For Online Training ► Call: +91-6301921083
Subscribe to our channel and hit the bell 🔔🔔🔔 icon to get video updates.
💡 Visit Our Website
For Online Training: www.ashokit.in
💡 About Ashok IT :
Ashok IT is the No.1 quality training institute in India for the candidates who want to build their future in Information Technology. We are into online training, class room training, corporate training and one to one training with more passion and dedication. Ashok IT aims in providing best quality realtime oriented trainings on C, C++, Java, Spring , Spring REST, Spring Cloud, Microservices, Python, DJango, .Net, Angular, React JS, Salesforce, , Testing, Android, Docker, Kubernates, Manual Testing, Selenium and Digital Marketing.
-----------------------------------------------------------------------------------
💡 Our Online Training Features
🎈 Training with Real-time Working Professionals
🎈 Industry Matching use cases
🎈 Live Coding
🎈 Real-time Environment
🎈 Class Notes
🎈 Doubts Clarifications in Each Session
-----------------------------------------------------------------------------------
💡 Contact details:
☎ WhatsApp Number: +91-6301921083
► Website : www.ashokit.in
► Join with us in Telegram : bit.ly/3iP2KyA
► Like us in Facebook : bit.ly/3dw6R0A
► Follow us in Instagram : bit.ly/3jzEKl8
► Follow us in Twitter : bit.ly/2SDqdK4
💡 Welcome to Ashok IT..!! 💡
👉 Register Here For Online Training : bit.ly/3Crpgbr
🔥 Download Android App : bit.ly/3Z2vXcO
🔥 Download IOS App (MyInstitute) : apple.co/3IcEao3
👉 ORG Code For IOS : CNFXJ
🌐 Visit Our Website : ashokitech.com/
In hashMap the insertion order is not maintain, how can you be sure it will give your the First Non Repeated Char boss ????
public class practicee {
public static void main(String args[])
{
String s="AABCDBE";
int count=0;
char[] k =s.toCharArray();
for (int i = 0; i < k.length; i++) {
for (int j = 0; j < k.length; j++) {
if (k[i]==k[j]) {
count++;
}
}
if (count==1) {
System.out.println(k[i]);
break;
}
count=0;
}
}
}
this is my approach
Ur way of explaining or teaching is excellent 👌😉bro superb 👌👍👏, nobody is there ...
Shouldn't the map be LinkedHashMap so that it maintains the insertion order to correctly identify first non-repeated character?
Yes it should be😊
Excellent . Thanks sir
Thanks Bro. Your explanation is super cool.
Really superb
Tq Ashok bro
My approach :
String unique = "AABDCE";
for (int i = 0; i < unique.length(); i++) {
for (int j = i+1; j < unique.length(); j++) {
if(unique.charAt(i) != unique.charAt(j)) {
System.out.println("1st non repeating char is : "+unique.charAt(j));
return;
}
}
}
Using index Of method?
using this collection approach it won't give correct output , if the non repeated occurs at the first position , for example input = "kaabcdbe" output should be k but it would give c.
It is coming last non repeated char we need first non repeated characters
Could u correct the code thro hashmap
You can use j=i+1
same doubt
I don't think j=i+1 would work because in that case first iteration A and A would be compared in second iteration A and b would be compared and thus compiler would declare A as the first non repeating character.I am also not sure.
@@krishkhemani96 if we take j = i+1 then it will consider the last duplicate character as the first non-repeating character for eg It will consider 'A' of index 1 as a non-repeating character.
Your coding still needs some polishing, first approach you should have used j=i+1 and the second approach you should have used LinkedHashMap.
Yeass bro and the hashmap does not maintain insertion order right? How he got the answer bro..!
@@anbuv.g.k495 It will work 90% of the time, but in production setting you'll face reality.
I don't think j=i+1 would work because in that case first iteration A and A would be compared in second iteration A and b would be compared and thus compiler would declare A as the first non repeating character.I am also not sure.