I don't think I can use a deep Algorithm for Baidu interview questions, but I have a flexible idea. I have already posted the source code of five solutions on the front. I thought I could end up here, today, another student said a strange idea but a method that fits the meaning of the question .. Please refer to the comments on the Baidu developer interview questions about the elimination of 85% million interviewees, @ apollokk.
I have also discussed several methods after optimization. If you haven't read the article, you can take a look At Baidu developer interview questions (optimization). For a summary of this article, you can refer: baidu developers interview questions (Summary), of course, this question is still to post the complete code of the Apollo KK Method, because the idea is not difficult, I will not talk nonsense (by the way, the output results are unordered, but the results match the meaning of the question ..
See the source code below:
public class Baidu6{public static void main(String[] args){StringBuilder result=new StringBuilder(); for (int i = 3; i <= 100; i += 3) { if (i % 5 != 0) result.append(i + "*\r\n"); } for (int i = 5; i <= 100; i += 5) { if (i % 3 == 0) { result.append(i+ "*#\r\n"); } else { result.append(i+ "#\r\n"); } } System.out.println(result);}}
I have also sorted out the complete questions on www.marksaas.com on my blog. If you want to see the complete 6 methods (I just wrote them separately on csdn ), you can go to marksaas. If you have any mistakes, please correct them ..