关闭

CODE 119: Integer to Roman

Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. static List r2a = new ArrayList(); static { r2a.add(new R2A(1000, 'M')); r2a....
阅读(337) 评论(0)

CODE 118: Roman to Integer

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. static Map r2a = new HashMap(); static { r2a.put('I', 1); r2a.put('V', 5); ...
阅读(455) 评论(0)

CODE 117: Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings. public String longestCommonPrefix(String[] strs) { // Start typing your Java solution below // DO NOT wri...
阅读(495) 评论(0)

CODE 114: 4Sum

Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Elements ...
阅读(515) 评论(0)

CODE 115: 3Sum Closest

Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact...
阅读(318) 评论(0)

CODE 116: 3Sum

Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero. Note: Elements in a triplet (a,b,c)...
阅读(304) 评论(0)

CODE 113: Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent. A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string...
阅读(423) 评论(0)

CODE 112: Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the...
阅读(420) 评论(0)

CODE 111: Valid Parentheses

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all va...
阅读(478) 评论(0)

CODE 110: Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()...
阅读(436) 评论(0)

CODE 109: Merge k Sorted Lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. public ListNode mergeKLists(ArrayList lists) { // IMPORTANT: Please reset any member data you...
阅读(314) 评论(0)

CODE 108: Swap Nodes in Pairs

Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only constant space. Y...
阅读(435) 评论(0)

CODE 107: Reverse Nodes in k-Group

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is...
阅读(471) 评论(0)

CODE 106: Remove Duplicates from Sorted Array

Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length. Do not allocate extra space for another array, you must do this in place with...
阅读(462) 评论(0)

CODE 105: Remove Element

Given an array and a value, remove all instances of that value in place and return the new length. The order of elements can be changed. It doesn't matter what you leave beyond the new length. pu...
阅读(420) 评论(0)

CODE 104: Divide Two Integers

Divide two integers without using multiplication, division and mod operator. public int divide(int dividend, int divisor) { // IMPORTANT: Please reset any member data you declared, as // the s...
阅读(406) 评论(0)

CODE 103: Substring with Concatenation of All Words

You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without an...
阅读(384) 评论(0)

CODE 102: Next Permutation

public void nextPermutation(int[] num) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. List rest = new ArrayList();...
阅读(361) 评论(0)

CODE 101: Longest Valid Parentheses

Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring. For "(()", the longest valid parentheses substring is "()", wh...
阅读(294) 评论(0)

CODE 100: Search in Rotated Sorted Array

Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2). You are given a target value to search. If found in the array retur...
阅读(381) 评论(0)
199条 共10页首页 上一页 1 2 3 4 5 ... 下一页 尾页
    个人资料
    • 访问:99480次
    • 积分:2706
    • 等级:
    • 排名:第13836名
    • 原创:178篇
    • 转载:21篇
    • 译文:0篇
    • 评论:9条
    文章分类
    最新评论