- 博客(80)
- 资源 (1)
- 收藏
- 关注
原创 列表元素的删除操作for...remove
以下两段代码:listt=['a','b','a','b']for i in listt: if 'a'==i: listt.remove(i)print(listt)运行结果为:['b', 'b']而对于listt=['a','a','b','a','b']for i in listt: if 'a'==i:
2017-09-12 10:16:48
672
原创 TypeError: 'zip' object is not callable
>>> list=zip('1234','abc')>>> list(list)Traceback (most recent call last): File "", line 1, in list(list)TypeError: 'zip' object is not callable>>> l=zip('ab','123')>>> l>>> lis
2017-09-10 10:11:37
4165
1
原创 9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.public class Solution { public boolean isPalindrome(int x) { String s=Integer.toString(x); char[] a=s
2016-01-27 21:52:29
440
原创 8. String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca
2016-01-27 17:28:14
305
原创 7. Reverse Integer 翻转一个整数
Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321对于这道题目,如果超出整数限制,那么返回0public class Solution { public int reverse(int x) { int a=Math
2016-01-25 15:12:41
367
转载 6. ZigZag Conversion 之字形字符判断
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 for better legibility)P A H NA P L S I
2016-01-25 12:44:33
444
转载 5. Longest Palindromic Substring 找出给定字符串中最长的子字符串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.转载出处:http://www.cn
2016-01-24 19:45:04
441
原创 4. Median of Two Sorted Arrays 两个有序数组的中位数
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).public class Solution {
2016-01-24 15:46:06
255
原创 希尔排序
是从插入排序来的,对于插入排序,当待排记录数很小时,直接插入排序的效率较高;当待排序列按关键字基本有序时直接插入的效率也较高所以从这两点出发对直接插入排序进行了改进,便产生了希尔排序该方法的基本思想是:先将整个待排元素序列分割成若干个子序列(由相隔某个“增量”的元素组成)分别进行直接插入排序,然后依次缩减增量再进行排序,待整个序列中的元素基本有序(增量足够小)时,再对全体元素进行一次直接插
2016-01-18 15:25:07
258
原创 直接插入排序
//这是我自己写的直接插入排序,直接插入排序的思想就是 以第一个数为基准,把后边的数,插入到前边已经排好序的适当位置上,直到整个有序,稳定排序,时间复杂度为O(n^2)public class insertsort { public static void main(String args[]){ int[] array={34,3,53,2,23,7,1
2016-01-18 14:23:56
270
转载 3. Longest Substring Without Repeating Characters 无重复字符的最长子字符串
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For
2016-01-16 21:25:54
318
原创 2. Add Two Numbers 给定的两个链表是逆序排列的,相加后放在一个新的链表里边
You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a link
2016-01-16 18:13:06
387
原创 1. Two Sum 给定一个数组和一个数,输出两个和为给定数的数组元素的下标
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, where
2016-01-16 16:03:43
435
转载 java线程的两种创建方式
http://blog.youkuaiyun.com/touch_2011/article/details/68910261、通过实现Runnable接口线程创建(1).定义一个类实现Runnable接口,重写接口中的run()方法。在run()方法中加入具体的任务代码或处理逻辑。(2).创建Runnable接口实现类的对象。(3).创建一个Thread类的对象,需要封装前面Runnabl
2016-01-14 18:19:39
312
原创 n个人排成一圈,从1到3报数,数到3的人出列,输出最后剩下的哪个人是原来的第几号
public classcircleLeftPeople { public static void main(String[]args){ int n=3; //n为参加游戏的人数 int rem=n,count=1,cur=0; boolean[]input=newboolean[n];//用数组做标记
2016-01-13 12:52:40
1778
原创 找出一个数组里边和最大的子数组,输出最大和和子数组
public classmaxSumOfarray{ public static void main(String[]args){ int[]array={1,-2,3,10,-4,7,2,-5}; int max=Integer.MIN_VALUE; int lastmax=0,newmax=0;
2016-01-13 12:50:52
628
原创 去除字符串s1中包含的s2中的字符后输出s1
对于 s1 They arestudents. 和s2 aeiou ;去掉s1中包含的s2中的字符,输出Thy r stdnts.public classsubString{ public static void main(String[] args){ Strings1= "They are students.";
2016-01-13 12:49:32
1597
原创 快排
public class quicksort {public static void main(String[] args){ int[] list={34,3,53,2,23,7,14,10}; quicksort(list,0,list.length-1); for(int i=0;i System.out.p
2016-01-13 11:41:28
297
转载 Merge Sorted Array合并两个有序数组
Given two sorted integer arrays nums1 and nums2, merge nums2 intonums1 as one sorted array.Note:You may assume that nums1 has enough space (size that is greater or equal tom + n) to hold addit
2016-01-09 12:00:36
364
转载 Same Tree 判断俩树是不是一样
Given two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value./** * Defin
2016-01-08 22:39:32
364
转载 Symmetric Tree 是不是对称树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3But the following
2016-01-08 21:49:46
272
原创 Binary Tree Level Order Traversal 二叉树的层序遍历
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree {3,9,20,#,#,15,7}, 3 / \ 9 20 /
2016-01-08 19:45:34
304
原创 Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary 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 leaf node.因为有前边的一些练习,这道题目做起来简直是太简单。主要思路:用一
2016-01-08 15:30:45
365
原创 Binary Tree Level Order Traversal II 从底部倒着输出二叉树每一层的元素
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree {3,9,20,#,#,15,7},
2016-01-07 13:54:15
423
转载 Balanced Binary Tree 判断二叉树是否是高度相差不超过1的高度平衡的二叉树
Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees ofevery node never differ
2016-01-06 14:39:33
359
转载 Minimum Depth of Binary Tree 二叉树的最小深度
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.出处:http://www.programcreek.com/2013/02
2016-01-05 20:30:19
376
转载 Path Sum 一个树里边,看看有没有一条路径上边的和等于给定的数
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary tree and sum
2016-01-05 10:24:38
499
原创 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 element is
2016-01-04 22:39:46
255
转载 Pascal's Triangle II 输入一个整数,输出该整数对应行数的杨辉三角
Given an index k, return the kth row of the Pascal's triangle.For example, given k = 3,Return [1,3,3,1].转载出处:http://www.programcreek.com/2014/04/leetcode-pascals-triangle-ii-java/publi
2016-01-04 21:58:33
438
原创 Pascal's Triangle 杨辉三角,输入行号,输出相应的杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 用到了L
2016-01-04 20:19:42
752
原创 Valid Palindrome 有效回文串,只包括字母数字,不分大小写
Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.For example,"A man, a plan, a canal: Panama" is a palindrome."race a car" is not a
2016-01-03 17:30:01
358
转载 Min Stack 实现一个最小栈
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get
2016-01-03 12:54:53
1107
原创 Intersection of Two Linked Lists 判断两个单链表里边有没有重叠,返回重叠的第一个节点
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2016-01-02 17:14:56
837
转载 Compare Version Numbers 比较版本号,输入是以小数点为分隔符的字符串数字
Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and co
2016-01-01 17:44:32
1222
原创 Excel Sheet Column Title 把整数转换为大写字母的组合
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB /*String
2015-12-30 22:20:35
321
原创 Majority Element 找出一个数组中出现次数最多的元素
Given an array of size n, find the majority element. The majority element is the element that appears more than⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element alw
2015-12-30 20:57:05
336
原创 Excel Sheet Column Number 把大写字符串转换为整数
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z
2015-12-30 19:47:34
355
原创 Factorial Trailing Zeroes 阶乘的后边有几个0
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.//含因子5为几个就是几个0,像25*4=100,所以25含有2个5,http://www.zhihu.com/question/3
2015-12-30 18:07:16
262
原创 Rotate Array 数组以某个元素为节点进行前后反转
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to[5,6,7,1,2,3,4]. Note:Try to come up as many solutions as you ca
2015-12-30 16:10:08
257
转载 Reverse Bits 二进制数反转 比较多的位运算符的使用
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as0011100101
2015-12-29 23:06:28
652
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人