CareerCup
文章平均质量分 59
kpskylonely
写代码的人
展开
-
【2】Reverse a C-Style String
Question: Write code to reverse a C-Style String (C-String means that “abcd” is represented as five characters, including the null character )package CareerCup;public class ReverseCStyleStr {原创 2013-04-09 21:44:22 · 535 阅读 · 0 评论 -
【11】Delete a node in the middle of a single linked list
Question:Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node.EXAMPLE Input: the node ‘c’ from the linked list a->b->c->d->e package Career原创 2013-04-15 23:11:12 · 438 阅读 · 0 评论 -
【13】Find the start of loop
Question:Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.DEFINITION:Circular linked list: A (corrupt) linked list in which a node’s next pointer原创 2013-04-23 21:59:36 · 694 阅读 · 0 评论 -
【12】Adds two numbers represented by a linked list and returns the sum as a linked list
Question:You have two numbers represented by a linked list, where each node contains a single digit. The digits are stored in reverse order, such that the 1’s digit is at the head of the list. Write原创 2013-04-15 23:14:28 · 367 阅读 · 0 评论 -
【14】Use a single array to implement three stacks
Question:Describe how you could use a single array to implement three stacks. package CareerCup;public class OneArrayThreeStack { int[] array; int top1; int top2; int top3Left; int top3R原创 2013-04-27 22:37:17 · 672 阅读 · 0 评论 -
Java 实现堆栈和队列
1.堆栈package CareerCup;public class Stack { Node top; public Stack(){} public void push(int data) { Node node = new Node(data); node.next = top; top = node; } public Node pop() {原创 2013-04-27 22:39:17 · 504 阅读 · 0 评论 -
【15】Design a stack which has push pop min max
Question:How would you design a stack which, in addition to push and pop, also has functions which return the minimum and maximum elements? Push, pop, min, max should all operate inO(1) time. 思路:原创 2013-04-30 11:38:15 · 517 阅读 · 0 评论 -
【16】Set of stacks
Qustion:Imagine a (literal) stack of plates. If the stack gets too high, it might topple. There-fore, in real life, we would likely start a new stack when the previous stack exceedssome threshold. I原创 2013-05-01 13:21:11 · 514 阅读 · 0 评论 -
【17】Implement a MyQueue class which implements a queue using two stacks
Question:Implement a MyQueue class which implements a queue using two stackspackage CareerCup;public class MyQueue { private Stack s1; private Stack s2; public MyQueue(){} public void enque原创 2013-05-22 22:13:29 · 546 阅读 · 0 评论 -
Java 链表实现
先定义节点:package CareerCup;public class Node{ public Node next = null; public int data = 0; public Node(){} public Node(int data) { this.data = data; this.next = null; } public vo原创 2013-04-13 17:55:57 · 373 阅读 · 0 评论 -
【10】Find nth to last element of a singly linked list
Question:Implement an algorithm to find the nth to last element of a singly linked list. package CareerCup;public class FindNthToLast{ public FindNthToLast(){} public Node find(LinkedList原创 2013-04-13 18:37:19 · 510 阅读 · 0 评论 -
【1】Detect if a string has all unique characters
Question: Implement an algorithm to determine if a string has all unique characters. What if you can not use additional data structures?package CareerCup;public class UniqueChar { public UniqueC原创 2013-04-09 21:40:39 · 474 阅读 · 0 评论 -
【3】Remove the duplicate characters in a string
Question: 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 a原创 2013-04-09 21:47:54 · 870 阅读 · 0 评论 -
【5】Replace all spaces in a string with ‘%20’
Question:Write a method to replace all spaces in a string with ‘%20’. package CareerCup;public class ReplaceSpace { public ReplaceSpace(){} public String replace(String str) { String strRepl原创 2013-04-10 22:13:21 · 534 阅读 · 0 评论 -
【4】Decide if two strings are anagrams or not
Question: Write a method to decide if two strings are anagrams or not.package CareerCup;public class Anagram { public Anagram(){} public boolean detect(String str1, String str2) { if(str1.le原创 2013-04-10 22:09:25 · 651 阅读 · 0 评论 -
【6】Decide if one string is a rotation of another string or not
Question: Assume you have a method isSubstring which checks if one word is a substring ofanother. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 usingonly one call to is原创 2013-04-10 22:38:28 · 790 阅读 · 0 评论 -
【9】Delete duplicates from an unsorted linked list
Question: Write code to remove duplicates from an unsorted linked list. How would you solve this problem if a temporary buffer is not allowed?package CareerCup;import java.util.HashSet;public原创 2013-04-13 17:53:25 · 744 阅读 · 0 评论 -
【7】Rotate matrix by 90 degrees
Question: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?package CareerCup;publi原创 2013-04-13 15:18:48 · 811 阅读 · 0 评论 -
【8】set matrix's elements to 0
Question:Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column is set to 0.package CareerCup;public class setZero { public setZero(){} public int[][] set(i原创 2013-04-13 15:21:33 · 393 阅读 · 0 评论 -
【18】Sort a stack in ascending order
Question: Write a program to sort a stack in ascending order. You should not make any assumptions about how the stack is implemented. The following are the only functions that should be used to writ原创 2013-05-22 22:15:53 · 546 阅读 · 0 评论