03 2017 档案
摘要:public sealed class Single1{ public Single1(){} public static Single1 initarg = null; public static Single1 Initarg{ get{ if(initarg == null){ initarg
阅读全文
摘要://接口 public interface Comparable{ int compareTo(Object other); } //实现 class Employee implements Comparable<Employee>{ public int compareTo(Employee ot
阅读全文
摘要:例如有两个类: Employee:超类 Manager:子类 多态:一个Employee变量既可以继承Employee类对象,也能继承Manager类的对象。 Employee e; e = new Employee() e = new Manager() Manager boss = new Ma
阅读全文
摘要:(一)map map(a,b)可以理解为对b中的每一个元素执行a方法 例如 list = ["1","2","3","4"] 则 map(int, list)表示将list中的元素转为int 如 a = [1,2,3] b = [11,12,13] c = [21,22,23] def add(x1
阅读全文
摘要:输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树。假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建二叉树并返回。 考察动态规划,只需要顺着根节点找到下一层的“根节点”,返回给上
阅读全文
摘要:输入一个链表,从尾到头打印链表每个节点的值。 用list保存一下ListNode,然后反转,搞定~用时20ms
阅读全文
摘要:请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 实际上我们还需要知道replace替换的时候如何保障效率:本题考查的是从右往左替换,占用更少的时间空间复杂度
阅读全文
摘要:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 注:这种方法不是最好的,因为想先提交一个结果,没想到直接过了~ 其实还有更好的方法:以左下角的数字为起点,往上走均会变小,往右走均会
阅读全文
摘要:递归的话,只需要考虑第一个数字的两种情况:选择或者不选择
阅读全文
摘要:例如 SUM = 9 抽取组合为 3:9 2:5 4:4 (5+4=9) 0:1 1:3 2:5 (1+3+5=9) 本程序的思路是开一个数组,其下标表示1到m个数,数组元素的值为1表示其下标 代表的数被选中,为0则没选中。 首先初始化,将数组前n个元素置1,表示第一个组合为前n个数。 然后从左到右
阅读全文
摘要:(一)插入排序 每次循环之前,前面i位总是有序的。 (二)冒泡排序 每次循环,跟无序子list的首位比,每次循环有一个最值沉到/浮到这个首位 (三)快速排序 每次抽第一个数为flag,然后调整成左边比他小,右边比他大,随后递归 (四) 堆排序
阅读全文
摘要:Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000. Example: Example: Pyhton代码如下: 最初使用
阅读全文
摘要:例如: 可以使用分片符和步长符:来给字符串进行分片和定义步长 结果如下: 这里发现 没有输出1到9的逆序,这时将string[1:9]看成第一个字符串,然后转置就行了 用这个方法判断某个字符串的子串是否为回文串就很有灵性了
阅读全文
摘要: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 sh
阅读全文
摘要:Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the leng
阅读全文
摘要:You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contai
阅读全文
摘要:Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have ex
阅读全文
摘要://全排列的递归实现 #include #include #include void swi(char *a,char *b){ char temp; temp = *a; *a = *b; *b = temp; } bool Ischange(char *a,int begin,int end){ for(int i=begin; i<end; ...
阅读全文

浙公网安备 33010602011771号