
----- 经典面试算法
谙忆
公众号:程序编程之旅。曾经写过C、C++,使用过Cocos2dx开发过游戏、安卓端、IOS端、PC端页面均开发过。目前专注Java开发,SaaS内核、元数据的研究。偶尔玩玩爬虫
-
原创 经典算法面试题目-置矩阵行列元素为0(1.7)
题目Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.写一个函数处理一个MxN的矩阵,如果矩阵中某个元素为0,那么把它所在的行和列都置为0.解答简单题。遍历一次矩阵,当遇到元素等于0时,记录下这个元素对应的行和列。 可2016-07-31 23:15:146301
0
-
原创 经典算法面试题目-矩阵旋转90度(1.6)
题目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?一张图像表示成NxN的矩阵,图像中每个像素是4个字节,写一个函数2016-07-31 05:07:3224944
4
-
原创 经典算法面试题目-替换字符串的内容(1.5)
题目Write a method to replace all spaces in a string with ‘%20’.写一个函数,把字符串中所有的空格替换为%20 。解答简单题(有2种方法,一种时间耗费大些,一种空间耗费大点,根据需要去选择就好了)第一种方法:(需要一个多余的空间开销-就是多一个原字符串的开销) 先遍历一次字符串,得到空格个数,进而得到将空格转换成%20后的串长度 (每个空格2016-07-27 22:32:5412742
0
-
原创 经典算法面试题目-判断两个字符串是否是变位词(1.4)
题目Write a method to decide if two strings are anagrams or not.写一个函数判断两个字符串是否是变位词。解答变位词(anagrams)指的是组成两个单词的字符相同,但位置不同的单词。比如说, abbcd和abcdb就是一对变位词。 也就是说,2个字符串,不管排列顺序如何,只要全部的单个字符能对应上,就是一对变位词!该题目有两种做法:时间复杂2016-07-23 23:30:1915491
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 no2016-07-22 14:40:2114145
0
-
原创 经典算法面试题目-翻转一个C风格的字符串(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风格的字符串。(C风格的意思是”abcd”需要用5个字符来表示,包含末尾的 结束字符)解答: 这道题如果2016-07-20 16:21:225524
0
-
原创 经典算法面试题目-判断一个字符串中的字符是否唯一(1.1)
题目: Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?实现一个算法来判断一个字符串中的字符是否唯一(即没有重复).不能使用额外的数据结构。 (即只使用基本的数据结构)解答: 首先,你2016-07-19 13:26:542467
0
-
原创 经典算法面试题目-判断s2是否是s1的旋转字符串(1.8)
题目Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 using only one call to isSubstr2016-08-05 23:28:409119
0