摘要: Write a method to replace all spaces in a string with'%20'. You may assume thatthe string has sufficient space at the end of the string to hold the dd... 阅读全文
posted @ 2015-09-16 21:07 whu.yt 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 初步思路:如果两个字符串长度不等,直接返回 false如果是 ascii 码,新建一个字母表大小的 int数组, 遍历一次字符串将相应数组元素值+1,然后在遍历另一个字符串,将相应数组元素值-1, 如果值已经为0,返回 false。时间复杂度: O(n)空间复杂度: O(1)public class... 阅读全文
posted @ 2015-09-16 19:57 whu.yt 阅读(198) 评论(0) 推荐(0) 编辑
摘要: 最初思路:先遍历一遍获得长度len, 第二次遍历只要遍历一半长度,将索引 k 位置元素与 len-1-k 位置元素互换void reverse(char* str) { int len = 0, i, k; // first traversal get length for (i... 阅读全文
posted @ 2015-09-16 19:30 whu.yt 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 思路: 假设给定字符串用的是ASCII编码,那么总共就只有256个字符,新建一个256个元素的boolean数组, 遍历字符串,将出现的字符在boolean数组所在位置置 1。如果碰到已经置一,表明出现重复字符,返回false。public class IsUniqueChars_1 { ... 阅读全文
posted @ 2015-09-16 15:33 whu.yt 阅读(185) 评论(0) 推荐(0) 编辑