Answers for "First non repeating Char"

0

First non repeating character position in a string

# First non repeating character position in a string

def first_non_repeating_letter(str)
    strL = str.downcase
    strL.each_char.with_index do |v, i|
        if strL.index(v) == strL.rindex(v)
            return i
        end
    end
    -1
end

print "First non repeating character position = ", 
	first_non_repeating_letter("abcdcba");  # 3
Posted by: Guest on October-07-2021
0

first none duplicated char

import java.util.Scanner;

public class FirstDuplicate
{
    private static Scanner scanner = new Scanner(System.in);
    public static void main(String[] args)
    {
        System.out.println("Enter random chars");
        String s = new String(scanner.nextLine());
        findTheFirstDublicate(s);

    }
    private static boolean findTheFirstDublicate(String s)
    {
        int[] arr = new int[26];

        for(int i=0 ; i<s.length() ; ++i)
        {
          int c =  s.charAt(i)-'a';
          ++arr[c];
        }
        pint(arr);
        return false;
    }

    private static void pint(int[] arr){
        int i = 0 ;
        while(i < arr.length){
            if(arr[i] == 1){
                System.out.println("First none duplicated letters "+((char)(i+'a')));
            }
            ++i;
        }
    }
}
Posted by: Guest on August-06-2021
0

First non repeating character position in a string

// First non repeating character position in a string
package main

import (
    "fmt";
    "strings"
)

func FirstNonRepeating(str string) int {
  strL := strings.ToLower(str)
  for i:= range str {
    count:=0
    for j:= range str {
      if strL[i] == strL[j] {
        count++
      }
    }
    if count == 1 {
      return i
    }
  }
return -1
}

func main() {
    fmt.Printf("First non repeating character position = %d", 
        FirstNonRepeating("abcdcba"))  // 3
}
Posted by: Guest on October-07-2021
0

First non repeating character position in a string

// First non repeating character position in a string

function first_non_repeating_letter(str) {
  for(var i = 0; i < str.length; i++) {
    if (str.indexOf(str[i]) === str.lastIndexOf(str[i])) {
      return i
    }
  }
  return null
}

console.log("First non repeating character position = " + 
    first_non_repeating_letter("abcdcba"));  //3
Posted by: Guest on October-08-2021

Code answers related to "First non repeating Char"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language