Anne

Anne.github.io


  • Home

  • About

  • Tags

  • Categories

  • Archives

Jobdu-1096-日期差值

Posted on 2018-06-18 | In Jobdu

Question

  • 题目描述:

    有两个日期,求两个日期之间的天数,如果两个日期是连续的我们规定他们之间的天数为两天

  • 输入:

    有多组数据,每组数据有两行,分别表示两个日期,形式为YYYYMMDD

  • 输出:

    每组数据输出一行,即日期差值

  • 样例输入:

    2011041220110422

  • 样例输出:

    11

Read more »

71.Simplify Path

Posted on 2018-06-17 | In LeetCode

Stack, Medium

Question

Given an absolute path for a file (Unix-style), simplify it.

For example,
path = "/home/", => "/home"
path = "/a/./b/../../c/", => "/c"

Corner Cases:

  • Did you consider the case where path = "/../"?
    In this case, you should return "/".
  • Another corner case is the path might contain multiple slashes '/' together, such as "/home//foo/".
    In this case, you should ignore redundant slashes and return "/home/foo".
Read more »

LeetCode-Java-Summary

Posted on 2018-06-17 | In LeetCode

ArrayList

constructor and iterator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.*;
class TestCollection1{
public static void main(String args[]){
ArrayList<String> list=new ArrayList<String>();//Creating arraylist
list.add("Ravi");//Adding object in arraylist
list.add("Vijay");
list.add("Ravi");
list.add("Ajay");
//Traversing list through Iterator
Iterator itr=list.iterator();
while(itr.hasNext()){
System.out.println(itr.next());
}
for(String str:list)
System.out.println(str);
}
}

(only haveadd(Element e) and addAll(Collection c), not addFirst(Element e))

Read more »

118.Pascal's Triangle

Posted on 2018-06-15 | In LeetCode

Question

Given a non-negative integer numRows, generate the first numRows of Pascal’s triangle.

img
In Pascal’s triangle, each number is the sum of the two numbers directly above it.

Example:

1
2
3
4
5
6
7
8
9
Input: 5
Output:
[
[1],
[1,1],
[1,2,1],
[1,3,3,1],
[1,4,6,4,1]
]
Read more »

160.Intersection of Two Linked Lists

Posted on 2018-06-13 | In LeetCode

Question

Write a program to find the node at which the intersection of two singly linked lists begins.

For example, the following two linked lists:

1
2
3
4
5
A: a1 → a2
↘
c1 → c2 → c3
↗
B: b1 → b2 → b3

begin to intersect at node c1.

Notes:

  • If the two linked lists have no intersection at all, return null.
  • The linked lists must retain their original structure after the function returns.
  • You may assume there are no cycles anywhere in the entire linked structure.
  • Your code should preferably run in O(n) time and use only O(1) memory.
Read more »

203.Remove Linked List Elements

Posted on 2018-06-12 | In LeetCode

Question

Remove all elements from a linked list of integers that have value val.

Example:

1
2
Input: 1->2->6->3->4->5->6, val = 6
Output: 1->2->3->4->5
Read more »

PAT-B-1008-数组元素循环右移问题

Posted on 2018-06-12 | In PAT-solutions

Question

1008 数组元素循环右移问题 (20)(20 分)

一个数组A中存有N(N&gt0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(M>=0)个位置,即将A中的数据由(A~0~ A~1~……A~N-1~)变换为(A~N-M~ …… A~N-1~ A~0~ A~1~……A~N-M-1~)(最后M个数循环移至最前面的M个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?

输入格式:每个输入包含一个测试用例,第1行输入N ( 1<=N<=100)、M(M>=0);第2行输入N个整数,之间用空格分隔。

输出格式:在一行中输出循环右移M位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。

输入样例:

1
2
6 2
1 2 3 4 5 6

输出样例:

1
5 6 1 2 3 4
Read more »

PAT-B-1006-换个格式输出整数

Posted on 2018-06-09 | In PAT-solutions

Question

让我们用字母B来表示“百”、字母S表示“十”,用“12…n”来表示个位数字n(&lt10),换个格式来输出任一个不超过3位的正整数。例如234应该被输出为BBSSS1234,因为它有2个“百”、3个“十”、以及个位的4。

输入格式:每个测试输入包含1个测试用例,给出正整数n(&lt1000)。

输出格式:每个测试用例的输出占一行,用规定的格式输出n。

输入样例1:

1
234

输出样例1:

1
BBSSS1234

输入样例2:

1
23

输出样例2:

1
SS123
Read more »

PAT-B-1004-成绩排名

Posted on 2018-06-09 | In PAT-solutions

Question

读入n名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。

输入格式:每个测试输入包含1个测试用例,格式为\

1
2
3
4
5
第1行:正整数n
第2行:第1个学生的姓名 学号 成绩
第3行:第2个学生的姓名 学号 成绩
... ... ...
第n+1行:第n个学生的姓名 学号 成绩

其中姓名和学号均为不超过10个字符的字符串,成绩为0到100之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。

输出格式:对每个测试用例输出2行,第1行是成绩最高学生的姓名和学号,第2行是成绩最低学生的姓名和学号,字符串间有1空格。

输入样例:

1
2
3
4
3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95

输出样例:

1
2
Mike CS991301
Joe Math990112
Read more »

234.Palindrome Linked List

Posted on 2018-06-07 | In LeetCode

Linked List, Easy

Question

Given a singly linked list, determine if it is a palindrome.

Example 1:

1
2
Input: 1->2
Output: false

Example 2:

1
2
Input: 1->2->2->1
Output: true
Read more »
1…789…14
Anne_ZAJ

Anne_ZAJ

boom pow

134 posts
14 categories
17 tags
0%
© 2019 Anne_ZAJ
Powered by Hexo
|
Theme — NexT.Pisces v5.1.3