cc.日常

八点起床终于去图书馆了

上午:

python学习

i=10
print(i)
print('helloworld')
print("helloworld")

print(1+100)

fp=open('C:/text.txt','a+')
print('helloworld',file=fp)
fp.close()

print('hello','world','python')

name='hello'
print(name)
print('标识',id(name))
print('类型',type(name))
print('值',name)
#二进制0b
#八进制0o
#十六进制0x

from decimal import Decimal
print(Decimal('1.1')*Decimal('2.2'))

name='张'
age=22
print('我叫'+name+',今年'+str(age)+'岁')

#str() 将其他数据类型转成字符串
#int() 将其他数据类型转成整数 文字和小数字符串无法转换为整数,浮点数转换为整数抹零取整
#float() 将其他数据类型转成浮点数 文字类无法转换成整数,整数转成浮点数末尾为.0

#单行注释
'''多行注释
多行注释
多行注释
'''
文件开头加中文声明注释用以指定源码文件的编码格式e.g.
#coding:utf-8

prsent=input('小张想要什么礼物')
print(prsent,type(prsent))

#从键盘输入两个整数,计算两个整数的和
a=int(input('输入加数:'))
#a=int(a)
b=int(input('输入另一个加数:'))
#b=int(b)
print(a+b)

print(a**b) #a的b次方
print(a//b) #整除
print(a%b) #取余

print(9//-4) #-3 一正一负整除公式 向下取整
print(-9//4) #-3

print(9%-4) #-3 公式 余数=被除数-除数*商
print(-9%4) #3

#赋值运算符 运算顺序从右到左
i=1+2
print(i)
a=b=c=10 #链式赋值,共用同一处内存空间
#参数赋值 += -+..
#系列解包赋值,左右个数相等否则报错
a,b,c=1,2,3
print(a,b,c)
# 交换 a,b=b,a

#比较运算符结果为bool类型
a,b=1,2
print('a==b?',a==b) #false
'''
=赋值运算符,==比较运算符
比较对象的标识 is
比较对象的值  ==
'''

#bool运算符
'''
and 两个运算数都为true结果为true
or  两个运算数有一个是true结果是true
not 运算数为t结果为f 运算数为f结果为t
'''

'''
位运算符
位与&  11->1
位或|  00->1 else 0
左移<< 高位溢出舍弃
右移>> 低位移除舍弃
'''

#优先级 算术运算>位运算>比较运算>布尔运算>赋值

#程序结构:顺序结构
print('-----------------start----------------')
print('step1')
print('step2')
print('step3')
print('-----------------end----------------')

#测试对象的布尔值
print(bool(False))  #False
print(bool(0))  #False
print(bool(0.0))  #False
print(bool(None))  #False
print(bool(''))  #False
print(bool(""))  #False
print(bool([]))  #False 空列表
print(bool(list()))  #False  空列表
print(bool(tuple()))  #False  空元组
print(bool({}))  #False  空字典
print(bool(dict()))  #False  空字典
print(bool(set()))  #False  空集合
#其余其他全部为true

#程序结构:选择结构 双分支结构
n=int(input('请输入一个整数'))
if n%2==0:
    print(n,'是偶数')
else:
    print(n,'是奇数')

#程序结构:选择结构 多分支结构 多选一执行
n=int(input('请输入成绩'))
if n>=80 and n<=100:
    print('A')
elif n<=79 and n>=60:
    print('B')
elif n<=59 and n>=0:
    print('不及格')
else:
    print('对不起,程序错误')

下午:

刷算法题 leetcode

1.二叉树层序遍历

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */


/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** levelOrder(struct TreeNode* root, int* returnSize, int** returnColumnSizes){
    *returnSize=0;
    if(root==NULL)
        return NULL;
    int**res=(int**)malloc(sizeof(int*)*2000);
    *returnColumnSizes=(int*)malloc(sizeof(int)*2000);
    struct TreeNode*queue[2000];
    int front=0,rear=0;
    struct TreeNode*cur;

    queue[rear++]=root;
    while(front!=rear){
        int colSize=0,last=rear;
        res[*returnSize]=(int*)malloc(sizeof(int)*(last-front));
        while(front<last){
            cur=queue[front++];
            res[*returnSize][colSize++]=cur->val;
            if(cur->left!=NULL)
                queue[rear++]=cur->left;
            if(cur->right!=NULL)
                queue[rear++]=cur->right;
        }
        (*returnColumnSizes)[*returnSize]=colSize;
        (*returnSize)++;
    }
    return res;
}

读俞军《产品方法论》

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值