系列文章目录
前言
一、今天写的HackerRanker team 的算法,统计方法命名单词量。
首先对Java驼峰命名的对象变量或者是方法对象进行校验然后对命名中的单词进行技术统计。
一、使用步骤
1.引入库
代码如下 :
import java.util.HashMap;
import java.util.Map;
/**
* Created by Lenovo on 2023/5/7.
*/
public class HackerRankTestCamelCase {
public static void main(String[] args){
System.out.println("Hello World!");
String srcStr=" h3elloWorldCvvv ntTestRet";
Integer wordCntFroCamelStr = getWordCntFroCamelStr(srcStr);
System.out.println(wordCntFroCamelStr);
}
/**
* here is a sequence of words in CamelCase as a string of letters, , having the following properties:
It is a concatenation of one or more words consisting of English letters.
All letters in the first word are lowercase.
For each of the subsequent words, the first letter is uppercase and rest of the letters are lowercase.
* Given s, determine the number of words in s.
* constriants
* camelcase string
* str len 1<=strLen<=10to5
* @param s
* @return
*/
public static int getWordCntFroCamelStr(String s){
String trimStr = s.trim();
if(trimStr==n