陪朋友刷题,记录下。

1.
Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +, -, *, /. Each operand may be an integer or another expression.
Note:
Division between two integers should truncate toward zero.
The given RPN expression is always valid. That means the expression would always evaluate to a result and there won't be any divide by zero operation.
出错的地方:
Q1. memcmp的误用引发的内存堆栈溢出,可能由于编译器的差别,本地OK,valgrind ok,但是远端ERROR。
修复用strcmp,按字节比,直到1个到尾。

Q2. 二级指针的运用
char* acSrc[5] = {"2", "1", "+", "3", "*"};
char** ppTcSrc = NULL;
ppTcSrc = acSrc;

取“2”, “1” 这些成员,原先取 *ppTcSrc + 0, *ppTcSrc + 1
129 printf("%s ", *ppTcSrc);
(gdb) n
140 return 0;
(gdb) p *ppTcSrc
$1 = 0x400bcb "2"
(gdb) p *ppTcSrc + 1
$2 = 0x400bcc ""
(gdb) p *ppTcSrc + 2
$3 = 0x400bcd "1"
(gdb) p *ppTcSrc + 3
$4 = 0x400bce ""
(gdb) p *ppTcSrc + 4
$5 = 0x400bcf "3"
(gdb) p *ppTcSrc + 5
$6 = 0x400bd0 ""
(gdb) p *ppTcSrc + 6
$7 = 0x400bd1 "%s "
本意是ppTcSrc[0], ppTcSc[1]. ... 也可以写成*(ppTcSrc), *(ppTcSrc + 1)
(gdb) p *(ppTcSrc + 2)
$10 = 0x400ba0 "+"
(gdb) p ppTcSc[2]
No symbol "ppTcSc" in current context.
(gdb) p *(ppTcSrc + 2)
$11 = 0x400ba0 "+"
(gdb) p ppTcSrc[2]
$12 = 0x400ba0 "+"

## 还是要注意下, ppTcSrc 的类型是char*, 想下他的指向,他的自加是什么意思。

2.
leetcode 7:
Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000.
Q1:
AddressSanitizer: heap-buffer-overflow on address 0x602000000298 at pc 0x7f6c0babb79b bp 0x7ffdfb3aca30 sp 0x7ffdfb3ac1e0
原因分析:
memcmp 的S使用,可能是编译器差距,本地OK。
解决方法:memcmp -> strncmp

3.405. Convert a Number to Hexadecimal

Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s complement method is used.
Note:
All letters in hexadecimal (a-f) must be in lowercase.
The hexadecimal string must not contain extra leading 0s. If the number is zero, it is represented by a single zero character '0'; otherwise, the first character in the hexadecimal string will not be the zero character.
The given number is guaranteed to fit within the range of a 32-bit signed integer.
You must not use any method provided by the library which converts/formats the number to hex directly.
Example 1:
Input:
26

Output:
"1a"

-- 这个做的很开心,虽然折腾了下,但是还是搞定了。^_^
Q1:
# 负数问题
负数是有符号的,当想要转成字符串,需要先转成无符号的
# 补码问题
负数,计算机用补码表示。
$15 = -1
(gdb) p /x iRh
$16 = 0xffffffff
(gdb) p /x iRh>>4
$17 = 0xffffffff
# 值范围
unsigned int 0~4294967295
int 2147483648~2147483647
unsigned long 0~4294967295
long 2147483648~2147483647
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
unsigned long long的最大值:1844674407370955161
__int64的最大值:9223372036854775807
__int64的最小值:-9223372036854775808
unsigned __int64的最大值:18446744073709551615
# -2147483648的补码
if (num == -2147483648) return 0xFFFFFFFF80000000;

git 地址:

https://github.com/HellsingAshen/Myleetcode-cn

leetCode笔记--(1)的更多相关文章

  1. Leetcode 笔记 113 - Path Sum II

    题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...

  2. Leetcode 笔记 112 - Path Sum

    题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...

  3. Leetcode 笔记 110 - Balanced Binary Tree

    题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...

  4. Leetcode 笔记 100 - Same Tree

    题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...

  5. Leetcode 笔记 99 - Recover Binary Search Tree

    题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...

  6. Leetcode 笔记 98 - Validate Binary Search Tree

    题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...

  7. Leetcode 笔记 101 - Symmetric Tree

    题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...

  8. Leetcode 笔记 36 - Sudoku Solver

    题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...

  9. Leetcode 笔记 35 - Valid Soduko

    题目链接:Valid Sudoku | LeetCode OJ Determine if a Sudoku is valid, according to: Sudoku Puzzles - The R ...

  10. Leetcode 笔记 117 - Populating Next Right Pointers in Each Node II

    题目链接:Populating Next Right Pointers in Each Node II | LeetCode OJ Follow up for problem "Popula ...

随机推荐

  1. 收到微软寄来的MVP包裹

    经过一年多的艰苦努力,最终在7月份获得了微软SharePoint的MVP. 今天收到了微软从美国寄来的包裹. 内部图: 奖牌: 回忆过去一年.白天和客户撕逼,晚上回家写博客,或者翻译英文文章,去论坛回 ...

  2. gcc指定头文件路径及动态链接库路径

    gcc指定头文件路径及动态链接库路径   本文详细介绍了linux 下gcc头文件指定方法,以及搜索路径顺序的问题.另外,还总结了,gcc动态链接的方法以及路径指定,同样也讨论了搜索路径的顺序问题.本 ...

  3. 通过UrlRewriter配置MVC4伪静态

    有些项目须要设置静态.这样能够被站点收录了,提高站点的排名.内容. 假设地址后面有www.a.com/xx.html?id=1是不行,还是不能达到一些需求.怎么才干实现www.a.com/1/xx.h ...

  4. 使用 F# 列表

    使用 F# 列表 在 C# 中使用 F# 的列表,是全然可能的,可是,我建议不要用,由于,仅仅要再做一点,就会使事情在 C# 看来更加自然.比如,把列表转换成数组非常easy.用List.toArra ...

  5. hdu2276---Kiki & Little Kiki 2(矩阵)

    Problem Description There are n lights in a circle numbered from 1 to n. The left of light 1 is ligh ...

  6. 例题 2-1 aabb 2-2 3n+1问题

    例题2-1  aabb 输出全部形如aabb的四位全然平方数(即前两位数字相等,后两位数字也相等) #include <stdio.h> #include <stdlib.h> ...

  7. '无法将“vue”项识别为 cmdlet、函数、脚本文件或可运行程序的名称' 或 'vue不是内部或外部命令' 的解决方法

    如果在使用 vue 初始化项目的时候提示: vue : 无法将“vue”项识别为 cmdlet.函数.脚本文件或可运行程序的名称.请检查名称的拼写,如果包括路径,请确保路径正确,然后再试一次. 或者: ...

  8. actionbarsherlock示例

    package com.example.viewpagerandtabdemo; import java.util.ArrayList; import java.util.List; import a ...

  9. 网络 - 网关的作用、DNS的作用

    DNS的作用 域名系统.负责把域名翻译成ip,或者把ip翻译成域名. hosts文件用于静态的域名解析.优先级高于DNS解析. DNS服务器,负责解析域名到ip地址上. 114.114.114.114 ...

  10. ROS单线多拨pppoe

    #设置内网IP地址 / ip add add interface=ether1 address=192.168.0.254/255.255.255.0 #设置共享上网 / ip firewall na ...