Linux系统环境下使用iconv实现文件编码格式的转换

简介

Linux系统环境下,有很多处理文件编码格式的方法,比如vim中,使用“set fileencoding=utf-8”可以实现编码格式到UTF8格式的转换。但是个人觉得iconv更加好用些,下面就介绍下如何使用。

iconv使用方法

下面是iconv的使用方法,比较重要的参数就是 “-f”:给出输入文件的编码格式,比如GBK; “-t”:指定输出文件的编码格式; “-o”:指定输出文件的文件名。

Read More

LeetCode Find Peak Element

Description

A peak element is an element that is greater than its neighbors.

Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.

The array may contain multiple peaks, in that case return the index to any one of the peaks is fine.

You may imagine that num[-1] = num[n] = -∞.

For example, in array [1, 2, 3, 1], 3 is a peak element and your function should return the index number 2.

The original problem is here.

The original code is here.

Read More

LeetCode Compare Version Numbers

Description

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 contain only digits and the . character.
The . character does not represent a decimal point and is used to separate number sequences.
For instance, 2.5 is not “two and a half” or “half way to version three”, it is the fifth second-level revision of the second first-level revision.

Here is an example of version numbers ordering:

0.1 < 1.1 < 1.2 < 13.37

The original problem is here.
The original code is here.

Read More

LeetCode Largest Number

Description

Given a list of non negative integers, arrange them such that they form the largest number.

For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.

Note: The result may be very large, so you need to return a string instead of an integer.

The original problem is here:

Read More

LeetCode Reverse Bits

Description

Reverse bits of a given 32 bits unsigned integer.

For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).

The original problem is here:

Read More

LeetCode Rotate Array

Description

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 can, there are at least 3 different ways to solve this problem.

The original problem is here:

Read More