编程题
文章平均质量分 66
wuliwpf
生命不息,学习不止。谨记!
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
设计一个二次方程计算器
题目描述:设计一个二次方程计算器输入:每个案例是关于x的一个二次方程表达式,为了简单,每个系数都是整数形式。输出:每个案例输出两个实数(由小到大输出,中间由空格隔开),保留两位小数;如果无解,则输出“No Solution”。样例输入:x^2+x=3x+4样例输出:-1.24 3.24注意要考虑系数是多位数字的情况。#include #incl原创 2016-02-05 12:03:59 · 809 阅读 · 0 评论 -
51. N-Queens
问题描述:The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens转载 2016-04-24 16:18:40 · 300 阅读 · 0 评论 -
[leetcode]382. Linked List Random Node
Given a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.Follow up:What if the linked list is extremely large and i转载 2016-08-16 23:24:08 · 308 阅读 · 0 评论 -
[编程题]跳石板
小易来到了一条石板路前,每块石板上从1挨着编号为:1、2、3.......这条石板路要根据特殊的规则才能前进:对于小易当前所在的编号为K的石板,小易单次只能往前跳K的一个约数(不含1和K)步,即跳到K+X(X为K的一个非1和本身的约数)的位置。 小易当前处在编号为N的石板,他想跳到编号恰好为M的石板去,小易想知道最少需要跳跃几次可以到达。如果不能到达,输出-1。例如:N = 4,M转载 2017-03-22 15:37:01 · 643 阅读 · 0 评论 -
[编程题]回文序列
如果一个数字序列逆置之后跟原序列是一样的就称这样的数字序列为回文序列。例如:{1, 2, 1}, {15, 78, 78, 15} , {112} 是回文序列, {1, 2, 2}, {15, 78, 87, 51} ,{112, 2, 11} 不是回文序列。现在给出一个数字序列,允许使用一种转换操作:选择任意两个相邻的数,然后从序列移除这两个数,并用这两个数字的和插入到这两个数之原创 2017-03-22 16:18:45 · 799 阅读 · 0 评论 -
[编程题]暗黑的字符串
一个只包含'A'、'B'和'C'的字符串,如果存在某一段长度为3的连续子串中恰好'A'、'B'和'C'各有一个,那么这个字符串就是纯净的,否则这个字符串就是暗黑的。例如:BAACAACCBAAA 连续子串"CBA"中包含了'A','B','C'各一个,所以是纯净的字符串AABBCCAABB 不存在一个长度为3的连续子串包含'A','B','C',所以是暗黑的字符串你的任务就是计算出长度转载 2017-03-22 18:18:10 · 346 阅读 · 0 评论 -
[leetcode]3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "转载 2017-03-31 00:07:16 · 219 阅读 · 0 评论 -
[leetcode]4. Median of Two Sorted Arrays
这个题是要求两个已排好序的数组合并之后的中位数,时间复杂度要为O(log(m+n))。转载 2017-04-02 21:18:59 · 272 阅读 · 0 评论 -
【leetcode】8. String to Integer (atoi)
https://leetcode.com/problems/string-to-integer-atoi/#/description题目是将字符串转成整型数,但是需要考虑多种样例输入。根据多次尝试,总结如下:首先将字符串首尾空格全部去掉;然后取它中从头开始到第一个非法字符(除数字0到9之外的数)之前的串,可以确定的是这个串的形式应该是:+/-xxxx或者是xxx或者直接是+/-。如果是+/-,原创 2017-05-02 18:42:03 · 255 阅读 · 0 评论 -
[leetcode]11. Container With Most Water
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 endpoints of line i is at (i, ai) and (i, 0转载 2017-05-03 17:15:46 · 304 阅读 · 0 评论 -
求二进制数中1的个数
给定一个一个字节(8位)的无符号整型数,求它的二进制数表示中1的个数。分析:一个比较容易想到的方法是从低位到高位判断是否为1,每得到一位就把这个数右移,这样只需取最低位即可。时间复杂度是O(logv),其中logv是这个数的位数。如果还想进一步降低时间复杂度,我们可以只关注那些数位上为1的位。对于一个二进制数(比如11010000),我们可以这样找到它里面的1:把这个数减一(11010000转载 2017-04-22 01:31:13 · 278 阅读 · 0 评论 -
KMP算法的Java实现
输入第一行一个整数N,表示测试数据组数。接下来的N*2行,每两行表示一个测试数据。在每一个测试数据中,第一行为模式串,由不超过10^4个大写字母组成,第二行为原串,由不超过10^6个大写字母组成。其中N输出对于每一个测试数据,按照它们在输入中出现的顺序输出一行Ans,表示模式串在原串中出现的次数。import java.util.Scanner;原创 2017-07-15 18:14:08 · 365 阅读 · 0 评论 -
[leetcode]141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?转自https://leetcode.com/discuss/32906/o-1-space-solution方法:使用两个指针:slow和fast。它俩都转载 2016-05-07 21:26:06 · 361 阅读 · 0 评论 -
[leetcode]337. House Robber III
The thief has found himself a new place for his thievery again. There is only one entrance to this area, called the "root." Besides the root, each house has one and only one parent house. After a tour原创 2016-05-06 22:26:40 · 335 阅读 · 0 评论 -
[leetcode]89. Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of原创 2016-05-17 16:48:00 · 389 阅读 · 0 评论 -
整除问题
题目描述:给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除。输入:两个整数n(2输出:一个整数.样例输入:6 10样例输出:1原创 2016-02-07 15:53:53 · 836 阅读 · 0 评论 -
后缀子串排序
题目描述:对于一个字符串,将其后缀子串进行排序,例如grain其子串有:grain rain ain in n然后对各子串按字典顺序排序,即: ain,grain,in,n,rain输入:每个案例为一行字符串。输出:将子串排序输出样例输入:grain样例输出:aingraininnrain#include #转载 2016-02-08 22:51:47 · 1922 阅读 · 0 评论 -
求图的顶点连通度和边连通度
思路:从网上找了一下大牛对于这类问题的总结:图的连通度问题是指:在图中删去部分元素(点或边),使得图中指定的两个点s和t不连通 (不存在从s到t的路径),求至少要删去几个元素。 图的连通度分为点连通度和边连通度: (1)点连通度:只许删点,求至少要删掉几个点(当然,s和t不能删去,这里保证原图中至少有三个点); (2)边连通度:只许删边,求至少要删掉几条边。 并且,转载 2016-03-18 15:59:42 · 8817 阅读 · 0 评论 -
大数的存储问题,计算1~40所有数的阶乘
采用int数组存储每一位,模拟乘法操作,逐位相乘,往前进位。原创 2016-03-21 19:11:09 · 7452 阅读 · 0 评论 -
217. Contains Duplicate
问题描述:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every e原创 2016-04-12 23:43:02 · 261 阅读 · 0 评论 -
260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given转载 2016-04-09 17:03:20 · 479 阅读 · 0 评论 -
319. Bulb Switcher
问题描述:There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or tur原创 2016-04-13 23:02:46 · 275 阅读 · 0 评论 -
198. House Robber
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 you from robbing each of them is that adjacent house原创 2016-04-28 17:04:49 · 283 阅读 · 0 评论 -
242. Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.Note:You may a原创 2016-04-10 21:59:02 · 319 阅读 · 0 评论 -
318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le转载 2016-04-16 22:05:56 · 262 阅读 · 0 评论 -
[leetcode]347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number原创 2016-05-28 16:47:20 · 338 阅读 · 0 评论 -
[leetcode]329. Longest Increasing Path in a Matrix
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of the boundary (i.e. wrap-around is not allowed).我们需要找到一个原创 2017-08-24 15:17:57 · 364 阅读 · 0 评论
分享