if length is equal and less than ill change code to: if (s.length()<=t.length())
so if they're ever equal and less than n output will be false as:
//return false if first i characters match
...
Type: Posts; User: drdre
if length is equal and less than ill change code to: if (s.length()<=t.length())
so if they're ever equal and less than n output will be false as:
//return false if first i characters match
...
code for find the shorter string:
if (s.length()<n || t.length()<n){
if (s.length()<t.length()){
n=s.length();
}else if(t.length()<s.length()){
...
Okay for the 4th Bulletpoint:
lessThan("bin", "binary", 4) is true but my console outputs false.
Lets say s="bin" and t="binary", we need to find the shortest length out of these two, S is the...
I know the problem with my code as for these:
My console prints:
lessThan("bin", "binary", 4) = false (which should be true)
lessThan("bit", "bitary", 4) = false (which should be true)
when...
Okay all the bullet points now work EXCEPT the 4th one:
lessThan("bin", "binary", 4) gives false in my console which should be true as bin comes before binary
and if I flip both strings to this:...
Does this solve the problem for this:
public boolean lessThan(String s, String t, int n) {
boolean lessThan = false;
if (s.length()<n || t.length()<n){
if...
Here my updated code:
public boolean lessThan(String s, String t, int n) {
boolean lessThan = false;
if (s.length()<n){
n = s.length();
}
for...
okay lets start with ("binary", "bind", 4) for n=4 if s.charAt(i) comes before t.charAt(i) it should return true if not then return false. but I'm not sure how to implement this.
would it be...
You should not use any other String methods apart from length() and charAt(), or the Java binarySearch method.
boolean lessThan(String s, String t, int n)
This method should return true if the...