摘要: Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees Can you do this in place?N*N的矩阵代表的图片,每个像素4 bytes, 旋转90度public statci void rotate(int [][] matrix, int n){ for (int layer =0; layer <n/2; ++layer){ int fi... 阅读全文
posted @ 2013-03-19 14:18 zhangfei2333 阅读(134) 评论(0) 推荐(0)
摘要: 将string里面的空格换为 %20确定长度,更换后+*2public static void ReplaceFun(char[] str, int length){ int spaceCount=0,newLength,i=0; for(i=0; i<length;i++) if(str[i]== ' '){ spaceCount++; } } newLength= length+spaceCount*2; str[newLenth]='\0'; for(i=length-1;i>=0;i--){ if... 阅读全文
posted @ 2013-03-03 22:36 zhangfei2333 阅读(131) 评论(0) 推荐(0)
摘要: 1.3 Design an algorithm and write code to remove the duplicate characters in a string without using any additional buffer NOTE: One or two additional variables are fine An extra copy of the array is not.FOLLOW UPWrite the test cases for this method设计一个算法,编程实现删除字符串中的重复字符,且不使用任何buffer。一两个字符空间可以,复制数组.. 阅读全文
posted @ 2013-03-03 21:59 zhangfei2333 阅读(144) 评论(0) 推荐(0)
摘要: 1.2 Write code to reverse a C-Style String (C-String means that “abcd” is represented as five characters, including the null character )写代码来反转一个C-style的字符串。void reverse(char *str){ char *end= str; char tmp; if(str){ while(*end){ ++end; } --end; while(... 阅读全文
posted @ 2013-01-14 10:41 zhangfei2333 阅读(96) 评论(0) 推荐(0)
摘要: 1.1 Implement an algorithm to determine if a string has all unique characters What if youcan not use additional data structures?实现一个算法,确定一个string是否由全部各不相同的字母(符号)组成,不能使用其他数据结构。简单方法,使用ASCII编码,相当于直接hashpublic static boolean isUniqueChars2(String str){ boolean[] char_set= new boolean[256]; for (... 阅读全文
posted @ 2013-01-12 22:22 zhangfei2333 阅读(109) 评论(0) 推荐(0)