国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

leetcode 58. Length of Last Word

2019-11-06 06:36:43
字體:
來源:轉載
供稿:網友
package com.bupt;//Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last Word in the string.////If the last word does not exist, return 0.////Note: A word is defined as a character sequence consists of non-space characters only.////For example, //Given s = "Hello World",//return 5.public class Solution {    public int lengthOfLastWord(String s) {    	int result = 0;    	if(s.length() == 0){    		return result;    	}    	char[] input = s.toCharArray();    	int size = input.length-1;    	while(size>=0 && input[size] == ' '){    		size--;    	}    	while(size>=0){    		if(input[size] == ' '){    			break;    		}    		result++;    		size--;    	}        return result;    }        public static void main(String[] args){    	Solution s = new Solution();    	System.out.PRintln(s.lengthOfLastWord(" "));    }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日土县| 新乡县| 扎赉特旗| 乌鲁木齐县| 丹寨县| 扶沟县| 大关县| 英超| 兴隆县| 随州市| 巧家县| 黄石市| 景德镇市| 资兴市| 泾源县| 隆安县| 若尔盖县| 项城市| 五原县| 得荣县| 化州市| 洱源县| 景东| 钟山县| 南靖县| 武川县| 台前县| 望城县| 闻喜县| 肥乡县| 罗源县| 万州区| 哈密市| 习水县| 南岸区| 海宁市| 楚雄市| 赣州市| 织金县| 万盛区| 平乐县|