10 2018 档案

摘要:There is a box protected by a password. The password is n digits, where each letter can be one of the first k digits 0, 1, ..., k 1. You can keep inpu 阅读全文
posted @ 2018-10-31 11:46 bernieloveslife 阅读(202) 评论(0) 推荐(0)
摘要:Given an n ary tree, return the preorder traversal of its nodes' values. For example, given a 3 ary tree: Return its preorder traversal as: [1,3,5,6,2 阅读全文
posted @ 2018-10-31 11:46 bernieloveslife 阅读(68) 评论(0) 推荐(0)
摘要:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation. Note: The given inte 阅读全文
posted @ 2018-10-31 11:46 bernieloveslife 阅读(99) 评论(0) 推荐(0)
摘要:You have a list of words and a pattern, and you want to know which words in words matches the pattern. A word matches the pattern if there exists a pe 阅读全文
posted @ 2018-10-31 11:46 bernieloveslife 阅读(87) 评论(0) 推荐(0)
摘要:Given an array A of non negative integers, half of the integers in A are odd, and half of the integers are even. Sort the array so that whenever A[i] 阅读全文
posted @ 2018-10-31 11:46 bernieloveslife 阅读(158) 评论(0) 推荐(0)
摘要:You are given a map in form of a two dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/ve 阅读全文
posted @ 2018-10-30 12:09 bernieloveslife 阅读(94) 评论(0) 推荐(0)
摘要:Given a List of words, return the words that can be typed using letters of alphabet on only one row's of American keyboard like the image below. Examp 阅读全文
posted @ 2018-10-30 12:09 bernieloveslife 阅读(99) 评论(0) 推荐(0)
摘要:A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com 阅读全文
posted @ 2018-10-30 12:09 bernieloveslife 阅读(149) 评论(0) 推荐(0)
摘要:Write a class StockSpanner which collects daily price quotes for some stock, and returns the span of that stock's price for the current day. The span 阅读全文
posted @ 2018-10-30 12:09 bernieloveslife 阅读(237) 评论(0) 推荐(0)
摘要:Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, empty slots are represented with '.'s. You may ass 阅读全文
posted @ 2018-10-30 12:09 bernieloveslife 阅读(144) 评论(0) 推荐(0)
摘要:X city opened a new cinema, many people would like to go to this cinema. The cinema also gives out a poster indicating the movies’ ratings and descrip 阅读全文
posted @ 2018-10-29 13:12 bernieloveslife 阅读(197) 评论(0) 推荐(0)
摘要:You are given an array A of strings. Two strings S and T are special equivalent if after any number of moves, S == T. A move consists of choosing two 阅读全文
posted @ 2018-10-29 13:12 bernieloveslife 阅读(117) 评论(0) 推荐(0)
摘要:Given an integer array with even length, where different numbers in this array represent different kinds of candies. Each number means one candy of th 阅读全文
posted @ 2018-10-29 13:12 bernieloveslife 阅读(87) 评论(0) 推荐(0)
摘要:Given a positive integer N, find and return the longest distance between two consecutive 1's in the binary representation of N. If there aren't two co 阅读全文
posted @ 2018-10-29 13:12 bernieloveslife 阅读(100) 评论(0) 推荐(0)
摘要:Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. Example 1: Inpu 阅读全文
posted @ 2018-10-29 13:12 bernieloveslife 阅读(137) 评论(0) 推荐(0)
摘要:题目描述 设有n个正整数,将他们连接成一排,组成一个最大的多位整数。 如:n=3时,3个整数13,312,343,连成的最大整数为34331213。 如:n=4时,4个整数7,13,4,246连接成的最大整数为7424613。 输入描述: 有多组测试样例,每组测试样例包含两行,第一行为一个整数N(N 阅读全文
posted @ 2018-10-28 14:10 bernieloveslife 阅读(159) 评论(0) 推荐(0)
摘要:题目描述 现在有一棵合法的二叉树,树的节点都是用数字表示,现在给定这棵树上所有的父子关系,求这棵树的高度 输入描述: 输入的第一行表示节点的个数n(1 ≤ n ≤ 1000,节点的编号为0到n 1)组成, 下面是n 1行,每行有两个整数,第一个数表示父节点的编号,第二个数表示子节点的编号 输出描述: 阅读全文
posted @ 2018-10-28 14:10 bernieloveslife 阅读(216) 评论(0) 推荐(0)
摘要:题目描述 春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的: “水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1^3+5^3+3^3。 现在要求输出所有在m和n范围内的水仙花数。 输入描述: 输入数据有多组,每组占一行,包括两个整数m和n(1 阅读全文
posted @ 2018-10-28 14:09 bernieloveslife 阅读(1066) 评论(0) 推荐(0)
摘要:题目描述 继MIUI8推出手机分身功能之后,MIUI9计划推出一个电话号码分身的功能:首先将电话号码中的每个数字加上8取个位,然后使用对应的大写字母代替 ("ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", 阅读全文
posted @ 2018-10-28 14:09 bernieloveslife 阅读(275) 评论(0) 推荐(0)
摘要:题目描述 给定一个句子(只包含字母和空格), 将句子中的单词位置反转,单词用空格分割, 单词之间只有一个空格,前后没有空格。 比如: (1) “hello xiao mi” “mi xiao hello” 输入描述: 输入数据有多组,每组占一行,包含一个句子(句子长度小于1000个字符) 输出描述: 阅读全文
posted @ 2018-10-28 14:09 bernieloveslife 阅读(312) 评论(0) 推荐(0)
摘要:题目描述 有一条彩色宝石项链,是由很多种不同的宝石组成的,包括红宝石,蓝宝石,钻石,翡翠,珍珠等。有一天国王把项链赏赐给了一个学者,并跟他说,你可以带走这条项链,但是王后很喜欢红宝石,蓝宝石,紫水晶,翡翠和钻石这五种,我要你从项链中截取连续的一小段还给我,这一段中必须包含所有的这五种宝石,剩下的部分 阅读全文
posted @ 2018-10-27 13:26 bernieloveslife 阅读(301) 评论(0) 推荐(0)
摘要:题目描述 一只袋鼠要从河这边跳到河对岸,河很宽,但是河中间打了很多桩子,每隔一米就有一个,每个桩子上都有一个弹簧,袋鼠跳到弹簧上就可以跳的更远。每个弹簧力量不同,用一个数字代表它的力量,如果弹簧力量为5,就代表袋鼠下一跳最多能够跳5米,如果为0,就会陷进去无法继续跳跃。河流一共N米宽,袋鼠初始位置就 阅读全文
posted @ 2018-10-27 13:26 bernieloveslife 阅读(708) 评论(0) 推荐(0)
摘要:题目描述 数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。 输入描述: 输入数据有多组,每组占一行,由两个整数n(n 阅读全文
posted @ 2018-10-27 13:26 bernieloveslife 阅读(194) 评论(0) 推荐(0)
摘要:题目描述 给定一个英文字符串,请写一段代码找出这个字符串中首先出现三次的那个英文字符(需要区分大小写)。 输入描述: 输入数据一个字符串,包括字母,数字等。 输出描述: 输出首先出现三次的那个英文字符 示例1 输入 Have you ever gone shopping and 输出 e 阅读全文
posted @ 2018-10-27 13:25 bernieloveslife 阅读(112) 评论(0) 推荐(0)
摘要:题目描述 给定一个十进制的正整数number,选择从里面去掉一部分数字,希望保留下来的数字组成的正整数最大。 输入描述: 输入为两行内容,第一行是正整数number,1 ≤ length(number) ≤ 50000。第二行是希望去掉的数字数量cnt 1 ≤ cnt 0: flag = False 阅读全文
posted @ 2018-10-27 13:25 bernieloveslife 阅读(218) 评论(0) 推荐(0)
摘要:Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a prime number of set bits in their binary representation 阅读全文
posted @ 2018-10-26 10:55 bernieloveslife 阅读(117) 评论(0) 推荐(0)
摘要:Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Input: 5 O 阅读全文
posted @ 2018-10-26 10:55 bernieloveslife 阅读(93) 评论(0) 推荐(0)
摘要:Given a string S, return the "reversed" string where all characters that are not a letter stay in the same place, and all letters reverse their positi 阅读全文
posted @ 2018-10-26 10:55 bernieloveslife 阅读(99) 评论(0) 推荐(0)
摘要:You're now a baseball game point recorder. Given a list of strings, each string can be one of the 4 following types: 1. Integer (one round's score): D 阅读全文
posted @ 2018-10-26 10:55 bernieloveslife 阅读(113) 评论(0) 推荐(0)
摘要:Given a non empty array of digits representing a non negative integer, plus one to the integer. The digits are stored such that the most significant d 阅读全文
posted @ 2018-10-26 10:54 bernieloveslife 阅读(97) 评论(0) 推荐(0)
摘要:Given a group of two strings, you need to find the longest uncommon subsequence of this group of two strings. The longest uncommon subsequence is defi 阅读全文
posted @ 2018-10-25 10:37 bernieloveslife 阅读(136) 评论(0) 推荐(0)
摘要:Given two strings s and t which consist of only lowercase letters. String t is generated by random shuffling string s and then add one more letter at 阅读全文
posted @ 2018-10-25 10:36 bernieloveslife 阅读(138) 评论(0) 推荐(0)
摘要:Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete th 阅读全文
posted @ 2018-10-25 10:36 bernieloveslife 阅读(296) 评论(0) 推荐(0)
摘要:On a N N grid, we place some 1 1 1 cubes. Each value v = grid[i][j] represents a tower of v cubes placed on top of grid cell (i, j). Return the total 阅读全文
posted @ 2018-10-25 10:36 bernieloveslife 阅读(115) 评论(0) 推荐(0)
摘要:A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only. We would like to convert the 阅读全文
posted @ 2018-10-25 10:36 bernieloveslife 阅读(179) 评论(0) 推荐(0)
摘要:Design a HashMap without using any built in hash table libraries. To be specific, your design should include these functions: put(key, value) : Insert 阅读全文
posted @ 2018-10-24 22:03 bernieloveslife 阅读(219) 评论(0) 推荐(0)
摘要:We are given two strings, A and B. A shift on A consists of taking string A and moving the leftmost character to the rightmost position. For example, 阅读全文
posted @ 2018-10-24 22:03 bernieloveslife 阅读(90) 评论(0) 推荐(0)
摘要:X is a good number if after rotating each digit individually by 180 degrees, we get a valid number that is different from X. Each digit must be rotate 阅读全文
posted @ 2018-10-24 22:03 bernieloveslife 阅读(141) 评论(0) 推荐(0)
摘要:Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Exa 阅读全文
posted @ 2018-10-24 22:02 bernieloveslife 阅读(119) 评论(0) 推荐(0)
摘要:Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all 阅读全文
posted @ 2018-10-24 22:02 bernieloveslife 阅读(135) 评论(0) 推荐(0)
摘要:Given a string S, we can transform every letter individually to be lowercase or uppercase to create another string. Return a list of all possible stri 阅读全文
posted @ 2018-10-23 11:04 bernieloveslife 阅读(126) 评论(0) 推荐(0)
摘要:Give a string s, count the number of non empty (contiguous) substrings that have the same number of 0's and 1's, and all the 0's and all the 1's in th 阅读全文
posted @ 2018-10-23 11:04 bernieloveslife 阅读(98) 评论(0) 推荐(0)
摘要:Given a word, you need to judge whether the usage of capitals in it is right or not. We define the usage of capitals in a word to be right when one of 阅读全文
posted @ 2018-10-23 11:03 bernieloveslife 阅读(100) 评论(0) 推荐(0)
摘要:Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. + + + + | Id(INT 阅读全文
posted @ 2018-10-23 11:03 bernieloveslife 阅读(99) 评论(0) 推荐(0)
摘要:Write a SQL query to find all duplicate emails in a table named Person. + + + | Id | Email | + + + | 1 | a@b.com | | 2 | c@d.com | | 3 | a@b.com | + + 阅读全文
posted @ 2018-10-23 11:03 bernieloveslife 阅读(129) 评论(0) 推荐(0)
摘要:Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and r 阅读全文
posted @ 2018-10-22 12:06 bernieloveslife 阅读(92) 评论(0) 推荐(0)
摘要:Given a non empty, singly linked list with head node head, return a middle node of linked list. If there are two middle nodes, return the second middl 阅读全文
posted @ 2018-10-22 12:06 bernieloveslife 阅读(90) 评论(0) 推荐(0)
摘要:Given an n ary tree, return the postorder traversal of its nodes' values. For example, given a 3 ary tree: Return its postorder traversal as: [5,6,3,2 阅读全文
posted @ 2018-10-22 12:06 bernieloveslife 阅读(92) 评论(0) 推荐(0)
摘要:We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would c 阅读全文
posted @ 2018-10-22 12:06 bernieloveslife 阅读(103) 评论(0) 推荐(0)
摘要:Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. E 阅读全文
posted @ 2018-10-22 12:06 bernieloveslife 阅读(88) 评论(0) 推荐(0)
摘要:Calculate the sum of two integers a and b, but you are not allowed to use the operator + and . Example 1: Input: a = 1, b = 2 Output: 3 Example 2: Inp 阅读全文
posted @ 2018-10-21 12:24 bernieloveslife 阅读(110) 评论(0) 推荐(0)
摘要:Write a program that outputs the string representation of numbers from 1 to n. But for multiples of three it should output “Fizz” instead of the numbe 阅读全文
posted @ 2018-10-21 12:24 bernieloveslife 阅读(122) 评论(0) 推荐(0)
摘要:Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped over it's main diagonal, switching the row and column ind 阅读全文
posted @ 2018-10-21 12:24 bernieloveslife 阅读(65) 评论(0) 推荐(0)
摘要:Given an array A of integers, for each integer A[i] we may choose any x with K 阅读全文
posted @ 2018-10-21 12:24 bernieloveslife 阅读(87) 评论(0) 推荐(0)
摘要:On a 2 dimensional grid with R rows and C columns, we start at (r0, c0) facing east. Here, the north west corner of the grid is at the first row and c 阅读全文
posted @ 2018-10-21 12:24 bernieloveslife 阅读(196) 评论(0) 推荐(0)
摘要:Given a non empty binary tree, return the average value of the nodes on each level in the form of an array. Example 1: Input: 3 / \ 9 20 / \ 15 7 Outp 阅读全文
posted @ 2018-10-20 11:51 bernieloveslife 阅读(83) 评论(0) 推荐(0)
摘要:Given an n ary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example, given a 3 ary tree: 阅读全文
posted @ 2018-10-20 11:51 bernieloveslife 阅读(73) 评论(0) 推荐(0)
摘要:Given an array nums of n integers where n 1, return an array output such that output[i] is equal to the product of all the elements of nums except num 阅读全文
posted @ 2018-10-20 11:51 bernieloveslife 阅读(79) 评论(0) 推荐(0)
摘要:On a N N grid, we place some 1 1 1 cubes that are axis aligned with the x, y, and z axes. Each value v = grid[i][j] represents a tower of v cubes plac 阅读全文
posted @ 2018-10-20 11:51 bernieloveslife 阅读(112) 评论(0) 推荐(0)
摘要:Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Given linked list head = [4,5,1,9], which 阅读全文
posted @ 2018-10-20 11:51 bernieloveslife 阅读(82) 评论(0) 推荐(0)
摘要:Given a non empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input 阅读全文
posted @ 2018-10-19 10:30 bernieloveslife 阅读(176) 评论(0) 推荐(0)
摘要:Implement a basic calculator to evaluate a simple expression string. The expression string may contain open ( and closing parentheses ), the plus + or 阅读全文
posted @ 2018-10-19 10:29 bernieloveslife 阅读(110) 评论(0) 推荐(0)
摘要:Implement a basic calculator to evaluate a simple expression string. The expression string contains only non negative integers, +, , , / operators and 阅读全文
posted @ 2018-10-19 10:29 bernieloveslife 阅读(86) 评论(0) 推荐(0)
摘要:Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R = L). You might 阅读全文
posted @ 2018-10-19 10:29 bernieloveslife 阅读(107) 评论(0) 推荐(0)
摘要:Given a directed, acyclic graph of N nodes. Find all possible paths from node 0 to node N 1, and return them in any order. The graph is given as follo 阅读全文
posted @ 2018-10-19 10:29 bernieloveslife 阅读(168) 评论(0) 推荐(0)
摘要:Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix. Note that it is th 阅读全文
posted @ 2018-10-18 11:23 bernieloveslife 阅读(87) 评论(0) 推荐(0)
摘要:Given a string, find the first non repeating character in it and return it's index. If it doesn't exist, return 1. Examples: s = "leetcode" return 0. 阅读全文
posted @ 2018-10-18 11:23 bernieloveslife 阅读(93) 评论(0) 推荐(0)
摘要:Given a binary search tree, write a function kthSmallest to find the kth smallest element in it. Note: You may assume k is always valid, 1 ≤ k ≤ BST's 阅读全文
posted @ 2018-10-18 11:23 bernieloveslife 阅读(71) 评论(0) 推荐(0)
摘要:Shuffle a set of numbers without duplicates. Example: // Init an array with set 1, 2, and 3. int[] nums = {1,2,3}; Solution solution = new Solution(nu 阅读全文
posted @ 2018-10-18 11:23 bernieloveslife 阅读(159) 评论(0) 推荐(0)
摘要:Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such that A[i] + B[j] + C[k] + D[l] is zero. To make pro 阅读全文
posted @ 2018-10-18 11:23 bernieloveslife 阅读(114) 评论(0) 推荐(0)
摘要:Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice ver 阅读全文
posted @ 2018-10-17 15:51 bernieloveslife 阅读(161) 评论(0) 推荐(0)
摘要:Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating 阅读全文
posted @ 2018-10-17 15:50 bernieloveslife 阅读(119) 评论(0) 推荐(0)
摘要:A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one p 阅读全文
posted @ 2018-10-17 15:50 bernieloveslife 阅读(145) 评论(0) 推荐(0)
摘要:You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1' 阅读全文
posted @ 2018-10-17 15:50 bernieloveslife 阅读(82) 评论(0) 推荐(0)
摘要:A matrix is Toeplitz if every diagonal from top left to bottom right has the same element. Now given an M x N matrix, return True if and only if the m 阅读全文
posted @ 2018-10-17 15:50 bernieloveslife 阅读(140) 评论(0) 推荐(0)
摘要:Given an array of non negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maxim 阅读全文
posted @ 2018-10-16 10:58 bernieloveslife 阅读(99) 评论(0) 推荐(0)
摘要:Given a linked list, reverse the nodes of a linked list k at a time and return its modified list. k is a positive integer and is less than or equal to 阅读全文
posted @ 2018-10-16 10:58 bernieloveslife 阅读(107) 评论(0) 推荐(0)
摘要:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a conca 阅读全文
posted @ 2018-10-16 10:58 bernieloveslife 阅读(115) 评论(0) 推荐(0)
摘要:Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and ' '. '?' Matches any single character. ' ' M 阅读全文
posted @ 2018-10-16 10:58 bernieloveslife 阅读(677) 评论(0) 推荐(0)
摘要:Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: 1. Each of the digits 阅读全文
posted @ 2018-10-16 10:58 bernieloveslife 阅读(180) 评论(0) 推荐(0)
摘要:Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the thr 阅读全文
posted @ 2018-10-15 10:34 bernieloveslife 阅读(147) 评论(0) 推荐(0)
摘要:Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives the s 阅读全文
posted @ 2018-10-15 10:34 bernieloveslife 阅读(177) 评论(0) 推荐(0)
摘要:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: 阅读全文
posted @ 2018-10-15 10:34 bernieloveslife 阅读(90) 评论(0) 推荐(0)
摘要:Given an array nums of n integers and an integer target, are there elements a, b, c, and d in nums such that a + b + c + d = target? Find all unique q 阅读全文
posted @ 2018-10-15 10:34 bernieloveslife 阅读(100) 评论(0) 推荐(0)
摘要:Given a linked list, remove the n th node from the end of list and return its head. Example: Given linked list: 1 2 3 4 5, and n = 2. After removing t 阅读全文
posted @ 2018-10-15 10:34 bernieloveslife 阅读(79) 评论(0) 推荐(0)
摘要:Given a collection of numbers that might contain duplicates, return all possible unique permutations. Example: Input: [1,1,2] Output: [ [1,1,2], [1,2, 阅读全文
posted @ 2018-10-14 10:42 bernieloveslife 阅读(67) 评论(0) 推荐(0)
摘要:Given a linked list, swap every two adjacent nodes and return its head. Example: Given 1 2 3 4, you should return the list as 2 1 4 3. Note: Your algo 阅读全文
posted @ 2018-10-14 10:42 bernieloveslife 阅读(82) 评论(0) 推荐(0)
摘要:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Input: [ 1 4 5, 1 3 4, 2 6 ] Output: 1 1 2 阅读全文
posted @ 2018-10-14 10:42 bernieloveslife 阅读(90) 评论(0) 推荐(0)
摘要:You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Note: You have to rotate the image in place, which 阅读全文
posted @ 2018-10-14 10:42 bernieloveslife 阅读(393) 评论(0) 推荐(0)
摘要:Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the 阅读全文
posted @ 2018-10-14 10:42 bernieloveslife 阅读(125) 评论(0) 推荐(0)
摘要:You are given a license key represented as a string S which consists only alphanumeric character and dashes. The string is separated into N+1 groups b 阅读全文
posted @ 2018-10-13 10:19 bernieloveslife 阅读(117) 评论(0) 推荐(0)
摘要:We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to guess which number I picked. Every time you guess wron 阅读全文
posted @ 2018-10-13 10:19 bernieloveslife 阅读(133) 评论(0) 推荐(0)
摘要:Given n non negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endp 阅读全文
posted @ 2018-10-13 10:18 bernieloveslife 阅读(104) 评论(0) 推荐(0)
摘要:Given an array A of non negative integers, return an array consisting of all the even elements of A, followed by all the odd elements of A. You may re 阅读全文
posted @ 2018-10-13 10:18 bernieloveslife 阅读(165) 评论(0) 推荐(0)
摘要:Given a non empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may a 阅读全文
posted @ 2018-10-13 10:18 bernieloveslife 阅读(102) 评论(0) 推荐(0)
摘要:Given a sorted (in ascending order) integer array nums of n elements and a target value, write a function to search target in nums. If target exists, 阅读全文
posted @ 2018-10-12 10:59 bernieloveslife 阅读(160) 评论(0) 推荐(0)
摘要:Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is define 阅读全文
posted @ 2018-10-12 10:59 bernieloveslife 阅读(229) 评论(0) 推荐(0)
摘要:Design a class to find the kth largest element in a stream. Note that it is the kth largest element in the sorted order, not the kth distinct element. 阅读全文
posted @ 2018-10-12 10:59 bernieloveslife 阅读(276) 评论(0) 推荐(0)
摘要:There are N network nodes, labelled 1 to N. Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v 阅读全文
posted @ 2018-10-12 10:59 bernieloveslife 阅读(214) 评论(0) 推荐(0)
摘要:In a row of seats, 1 represents a person sitting in that seat, and 0 represents that the seat is empty. There is at least one empty seat, and at least 阅读全文
posted @ 2018-10-12 10:59 bernieloveslife 阅读(195) 评论(0) 推荐(0)
摘要:Given two non empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a 阅读全文
posted @ 2018-10-11 10:26 bernieloveslife 阅读(123) 评论(0) 推荐(0)
摘要:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in or 阅读全文
posted @ 2018-10-11 10:25 bernieloveslife 阅读(137) 评论(0) 推荐(0)
摘要:You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo 阅读全文
posted @ 2018-10-11 10:25 bernieloveslife 阅读(89) 评论(0) 推荐(0)
摘要:Given an array of integers nums, write a method that returns the "pivot" index of this array. We define the pivot index as the index where the sum of 阅读全文
posted @ 2018-10-11 10:25 bernieloveslife 阅读(85) 评论(0) 推荐(0)
摘要:Design a HashSet without using any built in hash table libraries. To be specific, your design should include these functions: add(value): Insert a val 阅读全文
posted @ 2018-10-11 10:25 bernieloveslife 阅读(221) 评论(0) 推荐(0)
摘要:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and 阅读全文
posted @ 2018-10-10 10:52 bernieloveslife 阅读(103) 评论(0) 推荐(0)
摘要:The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id. + + + + + | 阅读全文
posted @ 2018-10-10 10:52 bernieloveslife 阅读(129) 评论(0) 推荐(0)
摘要:You are given a binary tree in which each node contains an integer value. Find the number of paths that sum to a given value. The path does not need t 阅读全文
posted @ 2018-10-10 10:51 bernieloveslife 阅读(100) 评论(0) 推荐(0)
摘要:We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1. Now, given an integer arra 阅读全文
posted @ 2018-10-10 10:51 bernieloveslife 阅读(98) 评论(0) 推荐(0)
摘要:Given a binary tree and a sum, find all root to leaf paths where each path's sum equals the given sum. Note: A leaf is a node with no children. Exampl 阅读全文
posted @ 2018-10-10 10:51 bernieloveslife 阅读(184) 评论(0) 推荐(0)
摘要:Given a function rand7 which generates a uniform random integer in the range 1 to 7, write a function rand10 which generates a uniform random integer 阅读全文
posted @ 2018-10-09 10:31 bernieloveslife 阅读(168) 评论(0) 推荐(0)
摘要:Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function 阅读全文
posted @ 2018-10-09 10:31 bernieloveslife 阅读(141) 评论(0) 推荐(0)
摘要:There is an m by n grid with a ball. Given the start coordinate (i,j) of the ball, you can move the ball to adjacent cell or cross the grid boundary i 阅读全文
posted @ 2018-10-09 10:31 bernieloveslife 阅读(126) 评论(0) 推荐(0)
摘要:Given a n ary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest le 阅读全文
posted @ 2018-10-09 10:31 bernieloveslife 阅读(90) 评论(0) 推荐(0)
摘要:Given an array, rotate the array to the right by k steps, where k is non negative. Example 1: Input: [1,2,3,4,5,6,7] and k = 3 Output: [5,6,7,1,2,3,4] 阅读全文
posted @ 2018-10-09 10:31 bernieloveslife 阅读(103) 评论(0) 推荐(0)
摘要: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: [ 阅读全文
posted @ 2018-10-08 13:00 bernieloveslife 阅读(172) 评论(0) 推荐(0)
摘要:A robot on an infinite grid starts at point (0, 0) and faces north. The robot can receive one of three possible types of commands: 2: turn left 90 deg 阅读全文
posted @ 2018-10-08 13:00 bernieloveslife 阅读(315) 评论(0) 推荐(0)
摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Given nums = [ 2, 0, 3, 5, 2, 1] sumRan 阅读全文
posted @ 2018-10-08 13:00 bernieloveslife 阅读(146) 评论(0) 推荐(0)
摘要:Given an array of strings, group anagrams together. Example: Input: ["eat", "tea", "tan", "ate", "nat", "bat"], Output: [ ["ate","eat","tea"], ["nat", 阅读全文
posted @ 2018-10-08 13:00 bernieloveslife 阅读(143) 评论(0) 推荐(0)
摘要:A message containing letters from A Z is being encoded to numbers using the following mapping: 'A' 1 'B' 2 ... 'Z' 26 Given a non empty string contain 阅读全文
posted @ 2018-10-08 13:00 bernieloveslife 阅读(270) 评论(0) 推荐(0)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple 阅读全文
posted @ 2018-10-07 12:47 bernieloveslife 阅读(446) 评论(0) 推荐(0)
摘要:Your are given an array of integers prices, for which the i th element is the price of a given stock on day i; and a non negative integer fee represen 阅读全文
posted @ 2018-10-07 12:47 bernieloveslife 阅读(125) 评论(0) 推荐(0)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction 阅读全文
posted @ 2018-10-07 12:46 bernieloveslife 阅读(105) 评论(0) 推荐(0)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple 阅读全文
posted @ 2018-10-07 12:46 bernieloveslife 阅读(125) 评论(0) 推荐(0)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may comple 阅读全文
posted @ 2018-10-07 12:46 bernieloveslife 阅读(170) 评论(0) 推荐(0)
摘要:Given an input string (s) and a pattern (p), implement regular expression matching with support for '.' and ' '. '.' Matches any single character. ' ' 阅读全文
posted @ 2018-10-06 13:22 bernieloveslife 阅读(144) 评论(0) 推荐(0)
摘要:You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points. Example: Input: points = [[ 阅读全文
posted @ 2018-10-06 13:22 bernieloveslife 阅读(100) 评论(0) 推荐(0)
摘要:You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c 阅读全文
posted @ 2018-10-06 13:22 bernieloveslife 阅读(98) 评论(0) 推荐(0)
摘要:A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bottom left corner, and (x2, y2) are the coordinates 阅读全文
posted @ 2018-10-06 13:22 bernieloveslife 阅读(117) 评论(0) 推荐(0)
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Note: Do not modify the linked list. Follow up: Can yo 阅读全文
posted @ 2018-10-06 13:22 bernieloveslife 阅读(100) 评论(0) 推荐(0)
摘要:In a deck of cards, each card has an integer written on it. Return true if and only if you can choose X = 2 such that it is possible to split the enti 阅读全文
posted @ 2018-10-05 11:11 bernieloveslife 阅读(493) 评论(0) 推荐(0)
摘要:Given a non negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Input: 5 Output: True E 阅读全文
posted @ 2018-10-05 11:11 bernieloveslife 阅读(80) 评论(0) 推荐(0)
摘要:The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font 阅读全文
posted @ 2018-10-05 11:11 bernieloveslife 阅读(83) 评论(0) 推荐(0)
摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example 1: Input: "babad" Output: 阅读全文
posted @ 2018-10-05 11:11 bernieloveslife 阅读(110) 评论(0) 推荐(0)
摘要:Given a non negative integer num, repeatedly add all its digits until the result has only one digit. Example: Input: 38 Output: 2 Explanation: The pro 阅读全文
posted @ 2018-10-05 11:11 bernieloveslife 阅读(88) 评论(0) 推荐(0)
摘要:Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example 1: Input: 16 Output: true Example 2: Input: 5 Output: 阅读全文
posted @ 2018-10-04 11:30 bernieloveslife 阅读(91) 评论(0) 推荐(0)
摘要:Given an integer, write a function to determine if it is a power of three. Example 1: Input: 27 Output: true Example 2: Input: 0 Output: false Example 阅读全文
posted @ 2018-10-04 11:30 bernieloveslife 阅读(123) 评论(0) 推荐(0)
摘要:Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built in library functio 阅读全文
posted @ 2018-10-04 11:29 bernieloveslife 阅读(137) 评论(0) 推荐(0)
摘要:Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n is positive and will fit within the range of a 32 b 阅读全文
posted @ 2018-10-04 11:29 bernieloveslife 阅读(97) 评论(0) 推荐(0)
摘要:Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example 阅读全文
posted @ 2018-10-04 11:29 bernieloveslife 阅读(79) 评论(0) 推荐(0)
摘要:Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Input: [10,2] Output: "210" Example 2: Input: [ 阅读全文
posted @ 2018-10-03 14:09 bernieloveslife 阅读(204) 评论(0) 推荐(0)
摘要:Given an unsorted array, find the maximum difference between the successive elements in its sorted form. Return 0 if the array contains less than 2 el 阅读全文
posted @ 2018-10-03 14:07 bernieloveslife 阅读(104) 评论(0) 推荐(0)
摘要:Given an integer n, return 1 n in lexicographical order. For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9]. Please optimize your algorith 阅读全文
posted @ 2018-10-03 14:06 bernieloveslife 阅读(99) 评论(0) 推荐(0)
摘要:International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ". ", "b" map 阅读全文
posted @ 2018-10-03 14:06 bernieloveslife 阅读(118) 评论(0) 推荐(0)
摘要:In the "100 game," two players take turns adding, to a running total, any integer from 1..10. The player who first causes the running total to reach o 阅读全文
posted @ 2018-10-03 14:05 bernieloveslife 阅读(135) 评论(0) 推荐(0)
摘要:题目描述: 现有公园游船租赁处请你编写一个租船管理系统。当游客租船时,管理员输入船号并按下S键,系统开始计时;当游客还船时,管理员输入船号并按下E键,系统结束计时。船号为不超过100的正整数。当管理员将0作为船号输入时,表示一天租船工作结束,系统应输出当天的游客租船次数和平均租船时间。 注意:由于线 阅读全文
posted @ 2018-10-02 11:22 bernieloveslife 阅读(271) 评论(0) 推荐(0)
摘要:统计一个给定字符串中指定的字符出现的次数。 测试输入包含若干测试用例,每个测试用例包含2行,第1行为一个长度不超过5的字符串,第2行为一个长度不超过80的字符串。注意这里的字符串包含空格,即空格也可能是要求被统计的字符之一。当读到'#'时输入结束,相应的结果不要输出。 对每个测试用例,统计第1行中字 阅读全文
posted @ 2018-10-02 11:21 bernieloveslife 阅读(234) 评论(0) 推荐(0)
摘要:给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内。长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内。 测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于 231;一对0 坐标标志着一个测试用例的 阅读全文
posted @ 2018-10-02 11:20 bernieloveslife 阅读(300) 评论(0) 推荐(0)
摘要:题目描述: 某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。 输入: 测试输入包含若干测试用例。每个测试用例的 阅读全文
posted @ 2018-10-02 11:18 bernieloveslife 阅读(161) 评论(0) 推荐(0)
摘要:读入一个只包含 +, -, *, / 的非负整数计算表达式,计算该表达式的值。 测试输入包含若干测试用例,每个测试用例占一行,每行不超过200个字符,整数和运算符之间用一个空格分隔。没有非法表达式。当一行中只有0时输入结束,相应的结果不要输出。 对每个测试用例输出1行,即该表达式的值,精确到小数点后 阅读全文
posted @ 2018-10-02 11:18 bernieloveslife 阅读(308) 评论(0) 推荐(0)
摘要:读入两个小于10000的正整数A和B,计算A+B。需要注意的是:如果A和B的末尾K(不超过8)位数字相同,请直接输出-1。 测试输入包含若干测试用例,每个测试用例占一行,格式为"A B K",相邻两数字有一个空格间隔。当A和B同时为0时输入结束,相应的结果不要输出。 对每个测试用例输出1行,即A+B 阅读全文
posted @ 2018-10-02 11:17 bernieloveslife 阅读(153) 评论(0) 推荐(0)
摘要:今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑每题的分值,所以并不是最后的排名。给定录取分数线,请你写程序找出最后通过分数线的考生,并将他们的成绩按降序打印。 测试输入包含若干场考试的信息。每场考试信息的第1行给出考生人数N ( 0 < N < 1000 ) 阅读全文
posted @ 2018-10-02 11:16 bernieloveslife 阅读(175) 评论(0) 推荐(0)
摘要:每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。现有一堆杂乱的机房签到、签离记录,请根据记录找出当天开门和关门的人。 测试输入的第一行给出记录的总天数N ( N> 0 ),下面列出了N天的记录。 每天的记录在第一行给出记录的条目数M (M > 0 ),下面是M行,每行的格式为 证件号码 阅读全文
posted @ 2018-10-02 11:15 bernieloveslife 阅读(271) 评论(0) 推荐(0)
摘要:给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j <= K。最大连续子序列是所有连续子序列中元素和最大的一个,例如给定序列{ -2, 11, -4, 13, -5, -2 },其最大连续子序列为 阅读全文
posted @ 2018-10-02 11:14 bernieloveslife 阅读(215) 评论(0) 推荐(0)
摘要:判断两序列是否为同一二叉搜索树序列 开始一个数n,(1<=n<=20) 表示有n个需要判断,n= 0 的时候输入结束。 接下去一行是一个序列,序列长度小于10,包含(0~9)的数字,没有重复数字,根据这个序列可以构造出一颗二叉搜索树。 接下去的n行有n个序列,每个序列格式跟第一个序列一样,请判断这两 阅读全文
posted @ 2018-10-02 11:13 bernieloveslife 阅读(144) 评论(0) 推荐(0)
摘要:题目描述: 按要求,给国家进行排名。 按要求,给国家进行排名。 有多组数据。 第一行给出国家数N,要求排名的国家数M,国家号从0到N-1。 第二行开始的N行给定国家或地区的奥运金牌数,奖牌数,人口数(百万)。 接下来一行给出M个国家号。 排序有4种方式: 金牌总数 奖牌总数 金牌人口比例 奖牌人口比 阅读全文
posted @ 2018-10-02 11:12 bernieloveslife 阅读(321) 评论(0) 推荐(0)
摘要:题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。 是否AC的规则如下: 1. zoj能AC; 2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空; 3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空 阅读全文
posted @ 2018-10-02 11:11 bernieloveslife 阅读(170) 评论(0) 推荐(0)
摘要:It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if y 阅读全文
posted @ 2018-10-02 11:10 bernieloveslife 阅读(135) 评论(0) 推荐(0)
摘要:给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。 现在请计算A+B的结果,并以正常形式输出。 输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。 请计算A+B的结果,并以正常形式输出,每组数据占一行。 阅读全文
posted @ 2018-10-02 11:09 bernieloveslife 阅读(228) 评论(0) 推荐(0)
摘要:Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, a 阅读全文
posted @ 2018-10-02 11:09 bernieloveslife 阅读(138) 评论(0) 推荐(0)
摘要:Grading hundreds of thousands of Graduate Entrance Exams is a hard work. It is even harder to design a process to make the results as fair as possible 阅读全文
posted @ 2018-10-02 11:08 bernieloveslife 阅读(150) 评论(0) 推荐(0)
摘要:This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns. The input consists of seve 阅读全文
posted @ 2018-10-02 11:07 bernieloveslife 阅读(193) 评论(0) 推荐(0)
摘要:读入两个不超过25位的火星正整数A和B,计算A+B。需要注意的是:在火星上,整数不是单一进制的,第n位的进制就是第n个素数。例如:地球上的10进制数2,在火星上记为“1,0”,因为火星个位数是2进制的;地球上的10进制数38,在火星上记为“1,1,1,0”,因为火星个位数是2进制的,十位数是3进制的 阅读全文
posted @ 2018-10-02 11:06 bernieloveslife 阅读(202) 评论(0) 推荐(0)
摘要:题目描述: To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the 阅读全文
posted @ 2018-10-02 11:05 bernieloveslife 阅读(132) 评论(0) 推荐(0)
摘要:Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, "helloworld" can be printed as: h d e l 阅读全文
posted @ 2018-10-02 11:04 bernieloveslife 阅读(175) 评论(0) 推荐(0)
摘要:如果A,B是C的父母亲,则A,B是C的parent,C是A,B的child,如果A,B是C的(外)祖父,祖母,则A,B是C的grandparent,C是A,B的grandchild,如果A,B是C的(外)曾祖父,曾祖母,则A,B是C的great-grandparent,C是A,B的great-gra 阅读全文
posted @ 2018-10-02 11:03 bernieloveslife 阅读(313) 评论(0) 推荐(0)
摘要:当n为3时,我们在验证xxx定律的过程中会得到一个序列,3,5,8,4,2,1,将3称为关键数,5,8,4,2称为覆盖数。现在输入n个数字a[i],根据关键数与覆盖数的理论,我们只需要验证其中部分数就可以确定所有数满足xxx定律,输出输入的n个数中的关键数。如果其中有多个关键数的话按照其输入顺序的逆 阅读全文
posted @ 2018-10-02 11:02 bernieloveslife 阅读(160) 评论(0) 推荐(0)
摘要:浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁. 输入包含多组测试用例. 每个用例首先包含2个整数n(0<n<=100000)和m(0<m<=10),其中: n为镇上的人数,m为需要找出的大富翁数, 接下来一行输入镇上n个人的财富值. n和m同时为0时表示输入结束. 请输出乌镇前m个大富翁的财产 阅读全文
posted @ 2018-10-02 11:02 bernieloveslife 阅读(426) 评论(0) 推荐(0)
摘要:读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当某个字符用完时,剩下的仍然按照ZOJ的顺序输出。 题目包含多组用例,每组用例占一行,包含ZOJ三个字符,当输入“E”时表示输入结束。 1<=length<=100。 对于每组输入,请输出一行,表示按照要求处理后的字符串 阅读全文
posted @ 2018-10-02 11:01 bernieloveslife 阅读(202) 评论(0) 推荐(0)
摘要:哈利波特在魔法学校的必修课之一就是学习魔咒。据说魔法世界有100000种不同的魔咒,哈利很难全部记住,但是为了对抗强敌,他必须在危急时刻能够调用任何一个需要的魔咒,所以他需要你的帮助。 给你一部魔咒词典。当哈利听到一个魔咒时,你的程序必须告诉他那个魔咒的功能;当哈利需要某个功能但不知道该用什么魔咒时 阅读全文
posted @ 2018-10-02 11:00 bernieloveslife 阅读(278) 评论(0) 推荐(0)
摘要:对于一个数n,如果是偶数,就把n砍掉一半;如果是奇数,把n变成 3*n+ 1后砍掉一半,直到该数变为1为止。 请计算需要经过几步才能将n变到1,具体可见样例。 测试包含多个用例,每个用例包含一个整数n,当n为0 时表示输入结束。(1<=n<=10000) 对于每组测试用例请输出一个数,表示需要经过的 阅读全文
posted @ 2018-10-02 11:00 bernieloveslife 阅读(188) 评论(0) 推荐(0)
摘要:省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。现得到城镇道路统计表,表中列出了任意两城镇间修建道路的费用,以及该道路是否已经修通的状态。现请你编写程序,计算出全省畅通需要的最低成本。 测试输入包含若干测试用例。每个测试用例的 阅读全文
posted @ 2018-10-02 10:59 bernieloveslife 阅读(222) 评论(0) 推荐(0)
摘要:现有一笔经费可以报销一定额度的发票。允许报销的发票类型包括买图书(A类)、文具(B类)、差旅(C类),要求每张发票的总额不得超过1000元,每张发票上,单项物品的价值不得超过600元。现请你编写程序,在给出的一堆发票中找出可以报销的、不超过给定额度的最大报销额。 测试输入包含若干测试用例。每个测试用 阅读全文
posted @ 2018-10-02 10:58 bernieloveslife 阅读(261) 评论(0) 推荐(0)
摘要:欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路。现给定一个图,问是否存在欧拉回路? 测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是节点数N ( 1 < N < 1000 )和边数M;随后的M行对应M条边,每行给出一对正整数,分别是该条边直接连通的两 阅读全文
posted @ 2018-10-02 10:58 bernieloveslife 阅读(166) 评论(0) 推荐(0)
摘要:题目描述: 省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可)。经过调查评估,得到的统计表中列出了有可能建设公路的若干条道路的成本。现请你编写程序,计算出全省畅通需要的最低成本。 输入: 测试输入包含若干测试用例。每个测试用例的第 阅读全文
posted @ 2018-10-02 10:57 bernieloveslife 阅读(359) 评论(0) 推荐(0)
摘要:给定两个字符串S1和S2,合并成一个新的字符串S。 合并规则为,S1的第一个字符为S的第一个字符,将S2的最后一个字符作为S的第二个字符; 将S1的第二个字符作为S的第三个字符,将S2的倒数第二个字符作为S的第四个字符,以此类推。 包含多组测试数据,每组测试数据包含两行,代表长度相等的两个字符串S1 阅读全文
posted @ 2018-10-02 10:55 bernieloveslife 阅读(225) 评论(0) 推荐(0)
摘要:输入两个多项式,计算它们的和。 每个多项式有若干对整数表示,每组整数中,第一个整数表示系数(非0),第二个整数表示该项的次数。 如由3 3 5 -2 1 4 0表示3x^5 - 2 * x + 4其中第一个3表示该多项式由三个整数对表示。 输入为两行,分别表示两个多项式。表示每项的整数对按照次数大小 阅读全文
posted @ 2018-10-02 10:54 bernieloveslife 阅读(308) 评论(0) 推荐(0)
摘要:输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m <10)进制数。 输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。 当m为0时输入结束。 输出格式:每个测试用例的输出占一行,输出A+B的m进制数。 阅读全文
posted @ 2018-10-02 10:53 bernieloveslife 阅读(252) 评论(0) 推荐(0)
摘要:求正整数N(N>1)的质因数的个数。 相同的质因数需要重复计算。如120=2*2*2*3*5,共有5个质因数。 可能有多组测试数据,每组测试数据的输入是一个正整数N,(1<N<10^9)。 对于每组数据,输出N的质因数的个数。 注意:1不是N的质因数;若N为质数,N是N的质因数。 阅读全文
posted @ 2018-10-02 10:52 bernieloveslife 阅读(336) 评论(0) 推荐(0)
摘要:题目描述: 给定两个正整数,计算这两个数的最小公倍数。 给定两个正整数,计算这两个数的最小公倍数。 输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数。 对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。 阅读全文
posted @ 2018-10-02 10:51 bernieloveslife 阅读(268) 评论(0) 推荐(0)
摘要:题目描述: 求A^B的最后三位数表示的整数。说明:A^B的含义是“A的B次方” 输入: 输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1<=A,B<=10000),如果A=0, B=0,则表示输入数据的结束,不做处理。 输出: 对于每个测试实例,请输出A^B的最后三位表示的整数, 阅读全文
posted @ 2018-10-02 10:50 bernieloveslife 阅读(121) 评论(0) 推荐(0)
摘要:写个算法,对2个小于1000000000的输入,求结果。 特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5 两个小于1000000000的数 输入可能有多组数据,对于每一组数据,输出Input中的两个数按照题目要求的方法进行运算后得到的结果。 阅读全文
posted @ 2018-10-02 10:48 bernieloveslife 阅读(132) 评论(0) 推荐(0)
摘要:在某个字符串(长度不超过100)中有左括号、右括号和大小写字母;规定(与常见的算数式子一样)任何一个左括号都从内到外与在它右边且距离最近的右括号匹配。写一个程序,找到无法匹配的左括号和右括号,输出原来字符串,并在下一行标出不能匹配的括号。不能匹配的左括号用"$"标注,不能匹配的右括号用"?"标注. 阅读全文
posted @ 2018-10-02 10:47 bernieloveslife 阅读(281) 评论(0) 推荐(0)
摘要:12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转。 第一行一个正整数表示测试数据的个数n。 只有n行,每行两个正整数a和b(0<a,b<=10000)。 如果满足题目的要求输出a+b的值,否则输出NO。 阅读全文
posted @ 2018-10-02 10:46 bernieloveslife 阅读(919) 评论(0) 推荐(0)
摘要:Find a longest common subsequence of two strings. First and second line of each input case contain two strings of lowercase character a…z. There are n 阅读全文
posted @ 2018-10-02 10:45 bernieloveslife 阅读(173) 评论(0) 推荐(0)
摘要:题目描述: We are all familiar with pre-order, in-order and post-order traversals of binary trees. A common problem in data structure classes is to find th 阅读全文
posted @ 2018-10-02 10:45 bernieloveslife 阅读(311) 评论(0) 推荐(0)
摘要:题目描述: You are given an unsorted array of integer numbers. Your task is to sort this array and kill possible duplicated elements occurring in it. 输入: F 阅读全文
posted @ 2018-10-02 10:43 bernieloveslife 阅读(131) 评论(0) 推荐(0)
摘要:Output the k-th prime number. k≤10000 The k-th prime number. 阅读全文
posted @ 2018-10-02 10:42 bernieloveslife 阅读(116) 评论(0) 推荐(0)
摘要:You are given a sequence of integer numbers. Zero-complexity transposition of the sequence is the reverse of this sequence. Your task is to write a pr 阅读全文
posted @ 2018-10-02 10:42 bernieloveslife 阅读(397) 评论(0) 推荐(0)
摘要:John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mat 阅读全文
posted @ 2018-10-02 10:41 bernieloveslife 阅读(307) 评论(0) 推荐(0)
摘要:Among grandfather's papers a bill was found. 72 turkeys $_679_ The first and the last digits of the number that obviously represented the total price 阅读全文
posted @ 2018-10-02 10:40 bernieloveslife 阅读(266) 评论(0) 推荐(0)
摘要:读入两个小于100的正整数A和B,计算A+B. 需要注意的是:A和B的每一位数字由对应的英文单词给出. 测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出. 对每个测试用例输出1行,即A+B的值. 阅读全文
posted @ 2018-10-02 10:37 bernieloveslife 阅读(229) 评论(0) 推荐(0)
摘要:某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。省政府“畅通工程”的目标是使全省任何两个城镇间都可以实现交通(但不一定有直接的道路相连,只要互相间接通过道路可达即可)。问最少还需要建设多少条道路? 测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是城 阅读全文
posted @ 2018-10-02 10:37 bernieloveslife 阅读(207) 评论(0) 推荐(0)
摘要:给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的。 输入n,m,点的编号是1~n,然后是m行,每行4个数 a,b,d,p,表示a和b之间有一条边,且其长度为d,花费为p。最后一行是两个数 s,t;起点s 阅读全文
posted @ 2018-10-02 10:36 bernieloveslife 阅读(193) 评论(0) 推荐(0)
摘要:对于一个字符串,将其后缀子串进行排序,例如grain 其子串有: grain rain ain in n 然后对各子串按字典顺序排序,即: ain,grain,in,n,rain 每个案例为一行字符串。 将子串排序输出 Solution1:(qsort) Solution2:(set) 阅读全文
posted @ 2018-10-02 10:34 bernieloveslife 阅读(914) 评论(0) 推荐(0)
摘要:在每年的校赛里,所有进入决赛的同学都会获得一件很漂亮的t-shirt。但是每当我们的工作人员把上百件的衣服从商店运回到赛场的时候,却是非常累的!所以现在他们想要寻找最短的从商店到赛场的路线,你可以帮助他们吗? 输入包括多组数据。每组数据第一行是两个整数N、M(N<=100,M<=10000),N表示 阅读全文
posted @ 2018-10-02 10:33 bernieloveslife 阅读(389) 评论(0) 推荐(0)
摘要:设计一个二次方程计算器 每个案例是关于x的一个二次方程表达式,为了简单,每个系数都是整数形式。 每个案例输出两个实数(由小到大输出,中间由空格隔开),保留两位小数;如果无解,则输出“No Solution”。 阅读全文
posted @ 2018-10-02 10:31 bernieloveslife 阅读(310) 评论(0) 推荐(0)
摘要:题目描述: 给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除。 两个整数n(2<=n<=1000),a(2<=a<=1000) 一个整数. 阅读全文
posted @ 2018-10-02 10:31 bernieloveslife 阅读(160) 评论(0) 推荐(0)
摘要:一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 每个案例第一行三个正整数N,M<=100,表示矩阵大小,和一个整数K 接下来N行,每行M个数,表示矩阵每个元素的值 输出最小面积的值。如果出现任意矩阵的和都小于K,直接输出-1。 阅读全文
posted @ 2018-10-02 10:29 bernieloveslife 阅读(615) 评论(0) 推荐(0)
摘要:题目描述: 对于一个不存在括号的表达式进行计算 存在多种数据,每组数据一行,表达式不存在空格 输出结果 阅读全文
posted @ 2018-10-02 10:29 bernieloveslife 阅读(274) 评论(0) 推荐(0)