LeetCode 1290. Convert Binary Number in a Linked List to Integer
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
int getDecimalValue(ListNode* head) {
int ans=0;
while(head!=NULL)
{
ans = (ans<<1)|(head->val);
head=head->next;
}
return ans;
}
};
LeetCode 1290. Convert Binary Number in a Linked List to Integer的更多相关文章
- 【leetcode】1290. Convert Binary Number in a Linked List to Integer
题目如下: Given head which is a reference node to a singly-linked list. The value of each node in the li ...
- [Algorithm] 1290. Convert Binary Number in a Linked List to Integer
Given head which is a reference node to a singly-linked list. The value of each node in the linked l ...
- 38. leetcode 405. Convert a Number to Hexadecimal
405. Convert a Number to Hexadecimal Given an integer, write an algorithm to convert it to hexadecim ...
- 【LeetCode】693. Binary Number with Alternating Bits 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 遍历判断 判断是否是交替模式 位运算 日期 题目地址 ...
- LeetCode 426. Convert Binary Search Tree to Sorted Doubly Linked List
原题链接在这里:https://leetcode.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/ 题目: C ...
- [leetcode]426. Convert Binary Search Tree to Sorted Doubly Linked List二叉搜索树转有序双向链表
Convert a BST to a sorted circular doubly-linked list in-place. Think of the left and right pointers ...
- LeetCode 405. Convert a Number to Hexadecimal (把一个数转化为16进制)
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s compl ...
- [LeetCode] 405. Convert a Number to Hexadecimal_Easy tag: Bit Manipulation
Given an integer, write an algorithm to convert it to hexadecimal. For negative integer, two’s compl ...
- [leetcode] 405. Convert a Number to Hexadecimal
https://leetcode.com/contest/6/problems/convert-a-number-to-hexadecimal/ 分析:10进制转换成16进制,不能用库函数,刚开始,我 ...
随机推荐
- EF中获取当前上下文的表名
EF在处理并发上并不是很好,很多时候我们需要手动写sql操作数据库.但是在基类中我们如何获取当前服务仓储操作的表呢? 使用正则是其中一种解决办法 Repository.Table是一条查询语句,通过t ...
- vuepress1.x入门使用
要点: 1.用npm操作会有各种问题,用yarn取代之; 2.yarn可以用npm全局安装,而npm是node环境自带,node环境去官网下载安装; 3.没有必要全局安装vuepress 操作: 1. ...
- springboot服务的一些问题
一: springboot踩坑记--springboot正常启动但访问404; 1. spring boot的启动类不能直接放在main(src.java.main)这个包下面,把它放在有包的里面就可 ...
- vue 地图可视化 maptalks 篇
Maptalks 项目是一个 HTML5 的地图引擎, 基于原生 ES6 Javascript 开发: - 二三维一体化地图, 通过二维地图的旋转 /倾斜增加三维视角 - 插件化设计, 能与其他图形库 ...
- 从0系统学 Android--1.1认识 Android
一转眼工作也有几年的时间了,一直想沉下心来,再回过头来重新系统的学习一遍 Android.所以就有了这个读书笔记.俗话说温故而知新,下面就请大家再跟着我系统的学习一篇 Android 吧! 这一系列主 ...
- Swift相比OC语言有哪些优点
Swift相比OC语言有哪些优点 1.自动做类型推断 2.可以保证类型使用安全 Swif类型说明符 --Swift增加了Tuple表示元组类型 --Swift增加了Optional表示可选类型 常量一 ...
- ESP8266与ESP8285开发时有什么区别
ESP8266模块在WiFi联网领域已经被广泛使用,但是ESP8266芯片是需要外挂Flash芯片的,这样就使模块不能做的更小.之后乐鑫公司又推出了ESP8285芯片,直接集成了1MByte的Flas ...
- 熟悉的味道——从Java单例写到C++单例
设计模式中,单例模式是常见的一种.单例模式需要满足以下两个条件: 保证一个类只能创建一个示例: 提供对该实例的全局访问点. 关于单例最经典的问题就是DCL(Double-Checked Lock),今 ...
- 安装fiddler后,willow安装
willow 安装需要与fiddler安装在同一个磁盘,如果出现报错找不到路径,请按下面地址下载willow后重新安装 willow下载地址: https://github.com/QzoneTouc ...
- 02-align-items的用法
侧轴是相对的 默认主轴是x 所以侧轴就是y轴 align-items设置侧轴上的子元素排列的方式(单行)纵轴方向上的对齐方式 align-items: flex-start; 顶部对齐 align-i ...