发文章
发文工具
撰写
网文摘手
文档
视频
思维导图
随笔
相册
原创同步助手
其他工具
图片转文字
文件清理
AI助手
留言交流
public static boolean isPalindrome(int x) { if (x < 0) { return false; } String s = String.valueOf(x); char[] chars = s.toCharArray(); int length = chars.length; for (int i = 0 ; i < length / 2; ++i) { if (chars[i] != chars[length - i -1]) { return false; } } return true; }
public static boolean isPalindrome1(int x) { if (x < 0) { return false; } String s = String.valueOf(x); char[] chars = s.toCharArray(); int start = 0; int end = chars.length - 1; while (start < end) { if (chars[start++] != chars[end--]) { return false; } } return true; }
来自: 陈喻 > 《待分类》
0条评论
发表
请遵守用户 评论公约
左旋转字符串
public class Solution { public String LeftRotateString(String str,int n) { if(str == null || str.length() == 0) { return "";} char[] chars = str.toCharArray();reverse(chars, n, ...
572,动态规划解分割回文串 III
动态规划最关键的是找出递推公式,当我们要求dp[i][j]的时候,只需要找出前m个字符分割成j-1个子串所修改的最小字符数+最后一个子串所需...
二、破坏回文串(Biweekly18)
if (null == palindrome || palindrome.length() == 0 || palindrome.length() == 1) {return te;}char tem[] = palindrome.toCharArray();// 尝试从前往后进行遍历for (int i = 0; i <tem.length; ...
228. Summary Ranges C#
public class Solution { public IList<string> SummaryRanges(int[] nums) { if(nums==null) { return null;Add(nums[nums.} int start=nums[0];
0131. Palindrome Partitioning (M)
Palindrome Partitioning (M)} private void dfs(String s, List<List<String>> ans, List<String> temp) { if (s.equals("")) { ans.add(new ArrayList<>(temp));b...
PHP 查找字符串常用函数介绍
string strstr ( string $haystack , mixed $needle [, bool $before_needle = false ] ) 注1:$haystack是当事字符串,$needle是被查找的字符串。六、strripos -计算指定字符串在目标字符串中最后一次...
回文算法
public void push(Object stack) {stackElem[top++] = stack;System.out.println("入栈" + stack);* public void isPalindrome2(String word) { int len = word.length();} if (word == rwor...
翻转单词顺序列
public class Solution { public String ReverseSentence(String str) { if(str == null || str.trim().length() == 0) { return str;} } // 对最后一个单词单独进行反转 reverse(chars, blank + 1, ch...
如何让textField输入框 限制输入字数的同时,还只让输入数字
如何让textField输入框 限制输入字数的同时,还只让输入数字。
微信扫码,在手机上查看选中内容