
ACM练习足迹
Turisla
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
HDOJ 1002 A + B Problem II
Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. InputThe first line of the input contains an integer原创 2015-01-22 10:00:38 · 440 阅读 · 0 评论 -
LeetCode P260 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原创 2015-12-05 16:01:00 · 421 阅读 · 0 评论 -
LeetCode P137 Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without usi原创 2015-12-05 15:59:44 · 424 阅读 · 0 评论 -
LeetCode P318 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原创 2017-03-13 11:36:06 · 396 阅读 · 0 评论 -
LeetCodeP22 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:"((()))", "(()())", "(())()", "()(())", "()原创 2017-03-13 11:37:29 · 359 阅读 · 0 评论 -
LeetCodeP89 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原创 2017-03-13 11:38:58 · 412 阅读 · 0 评论 -
腾讯2016研发工程师编程题(两题)
第一题在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同, 则称这种编码为格雷码(Gray Code),请编写一个函数,使用递归的方法生成N位的格雷码。给定一个整数n,请返回n位的格雷码,顺序为从0开始。测试样例:1返回:["0","1"]题解:该题考察格雷码生成规则。具体思想参考我的另一篇博文。本题注意以下几点:1、要求返回的是字符原创 2017-03-13 11:41:25 · 469 阅读 · 0 评论 -
二叉树三种遍历递归及非递归实现
二叉树的三种遍历方式包括:前序遍历中序遍历后序遍历三种遍历的递归方法都非常好实现,而且简单易懂。非递归实现也是通过使用栈来模拟遍历的过程。顺便提一句,能用递归做的,基本都能用栈来实现。前序遍历和中序遍历的非递归写法相对比较简单,只需要模拟遍历过程即可。后序遍历非递归写法比较难,需要借助一个辅助指针来记录右子树是否访问过,以防止重复访问陷入死循环。下面分别给出三种遍历方法的递归和非递原创 2017-03-13 11:48:34 · 655 阅读 · 0 评论 -
LeetCode P275 H-Index II
Follow up for H-Index: What if the citations array is sorted in ascending order? Could you optimize your algorithm?Hint:Expected runtime complexity is in O(log n) and the input is sorted.原创 2017-03-13 11:52:19 · 317 阅读 · 0 评论 -
LeetCodeP331 Verify Preorder Serialization of a Binary Tree
One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node’s value. If it is a null node, we record using a sentinel value such as #.原创 2017-03-13 11:56:22 · 310 阅读 · 0 评论 -
LeetCodeP134 Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to原创 2017-03-13 12:06:07 · 394 阅读 · 0 评论 -
各种排序算法总结
暂做笔记,以后再详细整理。一、插入排序1、直接插入排序public class InsertSort { public static void insertSort(int[] nums) { int size = nums.length; for (int i = 1; i < size; i++) { if原创 2017-03-13 12:12:13 · 338 阅读 · 0 评论 -
LeetCode P136 Single Number及异或知识
Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without using ext原创 2015-12-05 16:02:26 · 825 阅读 · 0 评论 -
JAVA读取文件中存在BOM的问题
最近在做项目的时候,需要从文件中读取中文字符然后处理。结果,当处理到文件开头的中文字符串的时候总是报错。调试的时候发现输出开头的字符串明明是一个中文字符,但是输出长度的时候却显示长度为2。于是将开头的字符串的两个字符分别输出,发现第一个字符是编码为65279的字符,输出以后感觉是没有长度的字符。第二个字符才是正确的目标字符。于是去网上查了下发现这个神秘的字符叫BOM。一下摘自百度百科:原创 2015-12-05 16:03:42 · 2288 阅读 · 0 评论 -
LeetCodeP079 Word Search
Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically原创 2015-12-30 15:30:17 · 592 阅读 · 0 评论 -
HDOJ 1004 Let the Balloon Rise
Problem DescriptionContest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest原创 2015-03-17 11:34:17 · 429 阅读 · 0 评论 -
王道1026 又一版 A+B
题目描述:输入两个不超过整型定义的非负10进制整数A和B(31-1),输出A+B的m (1 输入:输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。当m为0时输入结束。输出:输出格式:每个测试用例的输出占一行,输出A+B的m进制数。样例输入:8 1300 482 1 70样例输出:25041原创 2014-12-05 11:45:19 · 688 阅读 · 0 评论 -
冒泡排序总结
冒泡排序冒泡排序算法的运作如下:(从后往前)比较相邻的元素。如果第一个比第二个大,就交换他们两个。对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。在这一点,最后的元素应该会是最大的数。针对所有的元素重复以上的步骤,除了最后一个。持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较。算法实现: for原创 2015-04-27 17:18:07 · 784 阅读 · 0 评论 -
poj 2808题校门外的树(java)
先写上代码,用java写的:import java.util.*;import java.io.*;public class Main { public static void main(String []args)throws Exception{ Scanner input=new Scanner(System.in); int l=0,m=0,c,b,s=0; l=input.nextInt(); m=input.nextInt(); int a[]=new int [l+1]; for(原创 2011-05-04 13:30:00 · 1316 阅读 · 0 评论 -
poj 2750题鸡兔同笼(java)
<br />代码。<br />import java.util.*;<br />import java.io.*;<br />public class Main {<br /> public static void main(String []args)throws Exception{<br /> Scanner input=new Scanner(System.in);<br /> List list=new ArrayList();<br /> int n,min,max;<br /> n=i原创 2011-05-04 13:41:00 · 941 阅读 · 0 评论 -
poj 2714平均年龄(c)
<br />#include <stdio.h><br />#include <stdlib.h><br />int main(int argc, char *argv[])<br />{<br /> <br /> int n,b,a[100],i;<br /> double ave,s=0;<br /> scanf("%d",&n);<br /> b=n;<br /> while(n>0){<br /> for(i=0;i<b;i++){<br />原创 2011-05-16 22:44:00 · 667 阅读 · 0 评论 -
poj 2713肿瘤面积(java)
<br />import java.util.*;<br />import java.io.*;<br />public class Main {<br /> public static void main(String []args)throws Exception{<br /> Scanner input=new Scanner(System.in);<br /> int n,i1=0,j1=0,j2=0,i2=0,s,m=0;<br /> n=input.nextInt();<br /> <b原创 2011-05-16 22:46:00 · 1500 阅读 · 0 评论 -
poj 2742统计字符串数(c)
<br />#include <stdio.h><br />#include <stdlib.h><br />#include <string.h><br />int main(int argc, char *argv[])<br />{<br /> int n,i,a[26],j;<br /> char str[1001];//存放字符串 <br /> scanf("%d",&n);<br /> <br /> fflush(stdin);//清楚缓冲区的内容 <br /> <br /> whi原创 2011-05-18 13:49:00 · 1012 阅读 · 0 评论 -
poj 2701与七无关的数
<br />#include <stdio.h><br />#include <stdlib.h><br />int main(int argc, char *argv[])<br />{<br /> int a,i;<br /> long sum=0;<br /> int chashu(int n);<br /> scanf("%d",&a);<br /> for(i=1;i<=a;i++){<br /> if(chashu(i)!=0)<br /> sum=sum+i*原创 2011-05-23 15:00:00 · 870 阅读 · 0 评论 -
排序题
题目描述:对输入的n个数进行排序并输出。输入:输入的第一行包括一个整数n(1接下来的一行包括n个整数。输出:可能有多组测试数据,对于每组数据,将排序后的n个整数输出,每个数后面都有一个空格。每组测试数据的结果占一行。样例输入:41 4 3 2样例输出:1 2 3 4原创 2014-07-21 09:55:30 · 491 阅读 · 0 评论 -
判断链表是否为回文串以及关于回文串问题的讨论
最近在看程序员面试金典,在链表部分看到有一题问如何判断链表是否是回文串,然后想到白书中也有对最长回文子串的讨论,故想做一点总结。一、判断链表是否为回文串链表的数据结构是这样子滴:public class Node { public int val; public Node next; public Node(int val) {原创 2017-03-13 12:54:32 · 1051 阅读 · 0 评论