
coding interview
店小不2
这个作者很懒,什么都没留下…
展开
-
代码面试题:Majority Number
public int majorityNumber(int[] A){ if (A == null || A.length == 0) { return -1; } int candidate = 0; int count = 0; for (int i = 0; i < A.length; i++) { if原创 2014-09-04 08:48:52 · 1053 阅读 · 0 评论 -
代码面试题:Interleaving Negative and Positive Numbers 正负交替
Given an array with positive and negative integers. Resort the array so that原创 2014-09-11 13:21:34 · 2173 阅读 · 0 评论 -
代码面试题:Sort Letter
Given a string which contains only letters. Sort it by lower case first and upper case second.NoteIt's not necessary to keep the original order of lower-case letters and upper case letters.原创 2014-09-11 02:25:30 · 906 阅读 · 0 评论 -
代码面试题:Partition Array
Given an array "nums" of integers and an int "k", Partition the array (i.e move the elements in "nums") such that, * All elements * All elements >= k are moved to the rightReturn th原创 2014-09-11 02:01:39 · 789 阅读 · 0 评论 -
代码面试题:Majority Number III
Given an array of integers and a number k, the majority number is the number that occursmore than 1/k of the size of the array. Find it.NoteThere is only one majority number in the array.原创 2014-09-05 02:56:43 · 4264 阅读 · 0 评论 -
代码面试题:Reverse Linked List
Reverse a linked list. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL,return 5->4->3->2->1->NULL.原创 2014-09-20 12:43:03 · 600 阅读 · 0 评论 -
代码面试题:Fibonacci Numbers
public static ArrayList fibonacci(int num) { ArrayList res = new ArrayList(); if (num == 0) { return res; } int first = 0; int second = 1; if (num == 1) { res原创 2014-09-20 15:16:36 · 1016 阅读 · 0 评论 -
代码面试题:Rotate string by k element
public String rotateString(String A, int k) { if (A == null || k == 0) { return A; } k = k % A.length(); String result = new String(); result = A.substring(A.lengt原创 2014-09-20 08:31:01 · 523 阅读 · 0 评论 -
代码面试题:Insert Sorted Linked List
Insert a integer as a ListNode to a sorted linked list.原创 2014-09-20 08:07:40 · 763 阅读 · 0 评论 -
代码面试题:Subtree
Given two binary trees, check if the first tree is subtree of the second one. A subtree of a tree T is a tree S consisting of a node in T and all of its descendants in T. The subtree corresponding to原创 2014-09-20 06:13:42 · 638 阅读 · 0 评论 -
代码面试题:Delete duplicated char in string
public static String deleteDuplicate(String A) { if (A == null || A.length() <= 1) { return A; } char str[] = A.toCharArray(); LinkedHashSet hs = new LinkedHashSet(原创 2014-09-19 11:48:50 · 548 阅读 · 0 评论 -
代码面试题:Count ones in binary
Count the number of 1’s in the binary expression of a given integerExample: input: 90原创 2014-09-19 13:10:04 · 785 阅读 · 0 评论 -
代码面试题:Find the first element in a given string A that also appears in another given string B
public char firstAppear(String A, String B) { char res = '\0'; if (A == null || B == null) { return res; } for (int i = 0; i < A.length(); i++) { for (int j = 0;原创 2014-09-19 05:57:10 · 654 阅读 · 0 评论 -
代码面试题:Find two smallest number of an array
存两个变量。原创 2014-09-19 05:18:34 · 624 阅读 · 0 评论 -
代码面试题:Majority Number II
public int majorityNumber2(int[] A){ if (A == null || A.length == 0) { return -1; } int candidate1 = 0; int candidate2 = 0; int count1 = 0; int count2 = 0;原创 2014-09-04 10:08:03 · 3105 阅读 · 0 评论 -
代码面试题:find a peak (二分法)
Given an array of integers. Find a peak element in it. An array element is peak if it is NOT smaller than its neighbors. For corner elements, we need to consider only one neighbor. For example, for in原创 2014-09-17 11:25:31 · 1116 阅读 · 0 评论