Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Added tasks 345, 349. #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
javadev merged 10 commits into javadev:main from ThanhNIT:tasks-345-349
Dec 11, 2021
Merged

Added tasks 345, 349. #106

javadev merged 10 commits into javadev:main from ThanhNIT:tasks-345-349
Dec 11, 2021

Conversation

Copy link
Owner

@javadev javadev commented Dec 11, 2021

No description provided.

@Test
void reverseVowels() {
assertThat(
new g0301_0400.s0345_reverse_vowels_of_a_string.Solution().reverseVowels("hello"),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be class name without package.

@Test
void intersection() {
assertThat(
new g0301_0400.s0349_intersection_of_two_arrays.Solution()
Copy link
Owner Author

@javadev javadev Dec 11, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be a class name without package.

}
}
int[] result = new int[intersectionList.size()];
for (int i = 0; i < intersectionList.size(); i++) result[i] = intersectionList.get(i);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/main/java/g0301_0400/s0349_intersection_of_two_arrays/Solution.java:[20] (blocks) NeedBraces: 'for' construct must use '{}'s.

@javadev javadev changed the title (削除) Added tasks 345-349. (削除ここまで) (追記) Added tasks 345, 349. (追記ここまで) Dec 11, 2021
import java.util.ArrayList;
import java.util.List;

// #Easy #Array #Hash_Table #Sorting #Binary_Search #Two_Pointers
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move comment after package.

List<Integer> intersectionList = new ArrayList<>();

for (int j : nums1) {
for (int k : nums2) {
Copy link
Owner Author

@javadev javadev Dec 11, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use faster solution, this is too slow.

image

for (int j : nums1) {
for (int k : nums2) {
if (j == k && !intersectionList.contains(j)) {
intersectionList.add(j);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may use solution filter.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will update

javadev reacted with thumbs up emoji
i++;
j--;
}
return String.copyValueOf(str1);
Copy link
Owner Author

@javadev javadev Dec 11, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use this solution.

class Solution {
 private boolean isVowel(char c) {
 return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' 
|| c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
 }
 private StringBuilder swap(StringBuilder s, int l, int r) {
 char tmp = s.charAt(l);
 s.setCharAt(l, s.charAt(r));
 s.setCharAt(r, tmp);
 return s;
 }
 public String reverseVowels(String s) {
 int l = 0;
 int r = s.length() - 1;
 StringBuilder res = new StringBuilder(s);
 while (l < r) {
 while (l < r && !isVowel(s.charAt(l))) {
 l++;
 }
 while (l < r && !isVowel(s.charAt(r))) {
 r--;
 }
 res = swap(res, l, r);
 l++;
 r--;
 }
 return res.toString();
 }
}

Copy link
Owner Author

javadev commented Dec 11, 2021

You may use other email for commits

Thanh829 <tristian.ma@watasolutions.com>

git config user.name "John Doe"
git config user.email johndoe@example.com

static boolean isVowel(char c) {
return (c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I' || c == 'o'
|| c == 'O' || c == 'u' || c == 'U');
class Solution {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add public.

for(int i=0;i<nums1.length;i++) occ[nums1[i]]=true;
List<Integer> res=new ArrayList<>();
for(int i=0;i<nums2.length;i++){
if(occ[nums2[i]]){
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format source codes.

Copy link
Owner Author

javadev commented Dec 11, 2021

Theare are checkstyle warnings

Error: src/main/java/g0301_0400/s0349_intersection_of_two_arrays/Solution.java:[10,20] (misc) ArrayTypeStyle: Array brackets at illegal position.
Error: src/main/java/g0301_0400/s0349_intersection_of_two_arrays/Solution.java:[11] (blocks) NeedBraces: 'for' construct must use '{}'s.
Error: src/main/java/g0301_0400/s0349_intersection_of_two_arrays/Solution.java:[19,19] (misc) ArrayTypeStyle: Array brackets at illegal position.
Error: src/main/java/g0301_0400/s0349_intersection_of_two_arrays/Solution.java:[20] (blocks) NeedBraces: 'for' construct must use '{}'s.

Copy link
Owner Author

javadev commented Dec 11, 2021
edited
Loading

There is sonar warning

IMG_20211211_174200

Copy link

@javadev javadev merged commit df1e4d0 into javadev:main Dec 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
1 more reviewer

@ThanhNIT ThanhNIT ThanhNIT left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /