Menu Sidebar
Menu

strings

[LintCode] Valid Palindrome

public boolean isPalindrome(String s) { // Write your code here if(s.length() == 0 || s == null) return true; s = s.toLowerCase(); s = s.trim(); int i = 0; int j = s.length() – 1; while(i <= j) { while(i <= j && !((s.charAt(i) <= ‘z’ && s.charAt(i) >= ‘a’) || (s.charAt(i) >= ‘0’ && […]

[LintCode] Length of Last Word

public int lengthOfLastWord(String s) { // Write your code here if(s == null || s.length() == 0) return 0; for(int i = s.length()-1; i >=0; i–) { if(s.charAt(i) != ‘ ‘) { int res = 0; while(i >=0 && s.charAt(i) != ‘ ‘ ){ res++; i–; } return res; } } return 0; }

Older Posts

书脊

这青苔碧瓦堆, 俺曾睡风流觉, 将五十年兴亡看饱.

July 2024
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031