LeetCode 266. Palindrome Permutation (Algorithm Explained)

preview_player
Показать описание


Preparing For Your Coding Interviews? Use These Resources
————————————————————

Other Social Media
----------------------------------------------

Show Support
------------------------------------------------------------------------------

#coding #programming #softwareengineering
Рекомендации по теме
Комментарии
Автор

ty for the all the great explanations! u need to start a series of solving the cracking the code tech questions!

guguls
Автор

public class Solution {
public boolean canPermutePalindrome(String s) {
int value = 0;
for (int i = 0; i < s.length(); i++)
value = value ^ (int) s.charAt(i);
return || value == 0;
}
}
This was my solution Time Complexity O(n) and Space Complexity O(1)
P.S : I submitted it on lintCode, in Leetcode it's premium

HoussemNasrii
Автор

And after close to a year, I’m back here….and this guy is still #1!

samyakjain
Автор

Very hard to follow. Some visual representation would help.

Dislike.

kinnikuchu
Автор

if it's all lowercase you can just take one variable and set/reset the bits to keep track of multiples of 2 char counts. and check if the log of that number is integer or 0.

JSDev
Автор

why are we not doing chars_count[s.charAt(i) - 'a']++; ?? because char_count is an integer array, in order to convert a char to int index we need to subract by 'a' ??

shivadeepthitoopran
Автор

Could we use a HashMap to solve this problem?

KeenalShah
Автор

public class CanFormPalindrome {
public static boolean canFormPalindrome(String str) {
int char_counts[] = new int[128];
for(int i =0; i < str.length();i++) {

}
int count = 0;
for(int i = 0;i < 128;i++) {
count += char_counts[i] % 2;
}
return count <=0;
}
public static void main(String [] args) {

}
}
this is returning false can any one tell me how to rectify it

vedhlikith
Автор

this is premium.... is there a way to unlock premium without paying.. LOL

debayondharchowdhury
welcome to shbcf.ru